Data type is used for declaring the type of a variable. In C programming, data types are used to determine the type and size of data associated with a variable. It is important that the programmer decides the data type of a variable before storing any value.

Integer Data Types

Data TypeMemory Size (Bytes)Range
signed char1-128 to 127
unsigned char10 to 255
short int2-32,768 to 32,767
unsigned short int20 to 65,535
int4-2,147,483,648 to 2,147,483,647
unsigned int40 to 4,294,967,295
long8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long80 to 18,446,744,073,709,551,615
long long int8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long long int80 to 18,446,744,073,709,551,615

The above table represents the different types of integer data types, their memory size and the range of values they hold. Something to note here is that these datatypes and their memory size can vary between compiler designs. For example, the above is for gcc. There are other compilers like XC8 which has integer data types as below:

Data TypeSize in BitsData Range / Usage
unsigned char8-bit0 to 255
char8-bit-128 to +127
unsigned int16-bit0 to 65,535
int16-bit-32,768 to +32,767
unsigned short16-bit0 to 65,535
short16-bit-32,768 to +32,767
unsigned short long24-bit0 to 16,777,215
short long24-bit-8,388,608 to +8,388,607
unsigned long32-bit0 to 4,294,967,295
long32-bit-2,147,483,648 to +2,147,483,647

You can notice that there are different data types like short long, which is 3 bytes long. Similarly, below is another one from ARMCC:

TypeSize in BitsNatural Alignment in BytesRange of Values
char81 (byte-aligned)0 to 255 (unsigned) by default; -128 to 127 (signed) when compiled with --signed_chars
signed char81 (byte-aligned)-128 to 127
unsigned char81 (byte-aligned)0 to 255
(signed) short162 (halfword-aligned)-32,768 to 32,767
unsigned short162 (halfword-aligned)0 to 65,535
(signed) int324 (word-aligned)-2,147,483,648 to 2,147,483,647
unsigned int324 (word-aligned)0 to 4,294,967,295
(signed) long324 (word-aligned)-2,147,483,648 to 2,147,483,647
unsigned long324 (word-aligned)0 to 4,294,967,295
(signed) long long648 (doubleword-aligned)-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long long648 (doubleword-aligned)0 to 18,446,744,073,709,551,615

From all the above example, we can see that the integer data types differ across compilers. It is upto the compiler design to allocate different memory size and range of values. So it is important to understand the compiler that is being used.

Note

The C Standard does not specify the size of data types. They only give a range. For example, the standard can say that a long type can have a size between 32 and 64 bit long. Then the compiler designers can pick either a 32bit version, or a 64 bit version or different sizes in between. Int And Long Data Types shows what this means for int and long in practice.

Type By Type Notes

Each integer type is covered in its own note, one per lecture:

More types will be added here as the lectures cover them.

Previous: Escape Sequences