C Programming

data types

Every variable in C language is associated with data type. It represent type of data store in the variable. Program request the compiler to allocate memory require to store data according to the data type defined at the time of declaring variable. For example.

          int a;
          char b;

The above declaration represent  that a can store integer value and b cab store character value so program will request to compiler to allocate 2 bytes for int a and 1 byte for char  b in memory(memory means in RAM).  

There are the types of data type supported by C. we will learn only built-in data type in this section, user defined and drives types will be discussed in later part of the tutorial.

Table below list the basic data types with their size in bytes and the respective range of values.

typesize in bytesrange
char1-128 to +127
int2-32768 to + 32767
float43.4e-38 to 3.4e+38
double81.7e-308 to 1.7e+308

The C language has different qualifiers using which we can increase the range of data type. the qualifier are signed, unsigned, short and long. Table below lists the various data types by applying the qualifiers.

typesize in bytesrange
char(signed char)1-128 to +127
unsigned char10 to 255
int(signed int)2-32768 to +32767
unsigned int20 to 65535
short int (signed short int)2-32768 to +32767
unsigned short int20 to 65535
long int (signed long int)4-2147483648 to +2147483647
unsigned long int 40 to 4294967295
float43.4e-38 to 3.4e+38
double81.7e-308 to 1.7e+308
long double103.4E-4932 to 1.1E+4932

The type of the variable is chosen based on the type of information to be stored. To store the individual alphabets, char type is most suitable choice. The various int type are useful for whole numbers. The exact int type depends on the range in which your values are. For example, if the value remains in the range -32768 to +32767, the int (signed int) is most suitable choice. But if there are possibilities of exceeding this range, then either of the unsigned int, long int or unsigned long int may be chosen. The C supports float and double types for storing the real values. The float is single precision, while double is double precision. The precision shows the number of digits after decimal points. The accuracy increases as the number of digits after decimal point increases. The long double is the largest data type in C.