How To Guides

Integer Data Type in C Language

In C language the primary data types are of three types which are char, int and float. These primary data types can further be of several types like a char can be unsigned char or signed char. An int can be short int or long int.


C language provides a variations of the integer data type that will provide what is know as long or short integer values. These variations are provided for providing integers with different ranges wherever possible. There is no rule but generally short and long integers would occupy two and four bytes respectively. Every compiler can decide appropriate sizes which depends on the operating system and hardware for which it is being written. Long variables which has got long integers are declared by using the keyword long like in

long int i ;

long int abc ;

long integers can cause the program to run slowly but the range of the values that we can use is expanded greatly.

Short integers needs less space in the memory and they are declared as

short int j ;

short int height ;

C language lets you use abbreviation of short int to short and of long int to long. So the declaration that have been made above can be rewritten as

long i ;

long abc ;

short j ;

short height ;

This short-cut is preferred by most of the programmers.

Integers, signed and unsigned:

Sometimes a programmer already know that the value that has been stored in the gven integer variable will always be positive when it is used for counting things alone. In such scenarios you can declare variable to be unsigned like in,

unsigned int num_students ;

With this declaration the permissible integer values will be doubled. Like for 16-bit OS the range will shift from -32768 – +32768 to the range 0-65535. An unsigned integer occupies two bytes. You can declare an unsigned integer like this

unsigned int i ;

unsigned i ;