Datatype

Question & Answer

1.Types of DataTypes in C?
Primitive data type
Derived data type
User defined data type
Primitive data type
                char, int, float, double
Derived data type
                signed/unsigned char, signed/unsigned int, signed/unsigned long, long double
User defined data type
                structure, union, Enum, array

2. What is range of data types in c? How to find it? 

Below range & format specifier are based on 32 bit gcc compiler.
 
 DATA TYPE MEMORY (BYTES) RANGE FORMAT SPECIFIER
signed char 1 -128 to 127 %c
 unsigned char 0 to 255 %c
short int2 -32,768 to 32,767 %d
unsigned short int 2 0 to 65,535 %u
 unsigned int40 to 4,294,967,295  %u
 int4-2,147,483,648 to 2,147,483,647  %d
 float41.2E-38 to 3.4E+38  %f
 double82.3E-308 to 1.7E+308 %lf

To Find:
            For signed data types, 
                    -2^(n-1) to (2^(n-1))-1
            For unsigned data types, 
                    (2^n) – 1 
If we are minded the above formula we can easily find the range of datatype

Comments