Datatypes in c

datatypes in c

The kind of data that a variable can hold is called datatype. The data may be numeric or non-numeric or any type .the storage of separate data types will differ from machine to machine (64 bit and 32bit)Integer

  1. Primary (fundamental) data types.
  2. Derived data type.
  3. User-defined data type

Primary data types

Int : int is used to assign integers to a variable but without a decimal point

Float: float is used to indicate a floating point number .float can contain integers with decimal points .float store maximum 6 digits after decimal number

Double: double is used to indicate double precision floating point number .this keyword is used in case of more accuracy .for example in case of PI value .Double stores 16 digits after decimal point

Char: char is used to indicate character .this may be character constant or single constant .it is enclosed in a pair of single quotes

Data types in c

Modifiers

modifers are used to minimze the storage .modifiers are prefixed with basic datatypes to modify (either increase or decrease ) the storage size

there are four modifiers in c language

  • short
  • long
  • signed
  • unsigned

1. Short

short is used to decrease the memory size.int occupies 4bytes-64bit os,2bytes for 32bit os.if we use this short in 64bit ,size will be reduced 2

2.long

long is used to increase the size of the data type.this can be applied on int or double.if the size of int is 2 ,it changes to 4 bytes

3. Signed

This keyword accepts both negative or positive value and this is default properties or data type modifiers for every data type. in real time no need to write signed keyword explicitly for any data type.

example:

int a=10; // right
int a=-10; // right
signed int a=10; // right
signed int a=-10; // right

4.unsigned

This keyword can be used to make the accepting values of a data type is positive data type

example:

unsigned int a =100; // right
unsigned int a=-100; // wrong

below is the table for 16-bit processor.

Storage size and range for int and float datatype varies on 64-bit and 32-bit operating systems

datatyperangebytesFORMAT
signed char-128 to +1271%c
unsigned char0 to 2551%c
short signed int-32768 to +327672%d
short unsigned int0 to 655352%u
signed int-32768 to +327672%d
unsigned int0 to 655352%u
long signed int-2147483648 to +21474836474%ld
long unsigned int0 to 42949672954%lu
float-3.4e308 to +3.4e3084%f
double-1.7e308 to +1.7e3088%lf