The data types of a programming language determine the way a computer organizes data in its memory. C offers five basic data types:
- char
- int
- float
- double
- void
Each of these data types are represented differently within the computer memory. The following figure illustrates the data types in C:
The int Data Type
The int data type is the principal working type of C programming language. The other types, char, short, long and unsigned are the integral types working with the integer values that are representable on a machine. C offers many integer types, and one may wonder why one type isn’t enough. The answer is that C gives the programmer the option of matching a type to a particular use. In particular, the C integer types vary in the range of values offered and in whether negative numbers can be used or not. The int type is the basic choice, but if there arises a necessity to meet the requirements of a particular task or machine, there are other types available too.
The int type is a signed integer. This means that it must be an integer and it can be positive, negative or zero. The range in possible values depends upon the computer system. Typically, an int uses one machine word for storage. The int type represents an integer value, 2 bytes or 4 bytes. Integer typically reflects the natural size of integers on the host machine. It means that in the host with 16 bit system, the size of the integer is 2 bytes (16 bits) and in the machine with 32 bit system, the size of the integer is 4 bytes (32 bits). In the program executing in DOS (16 bit system), int takes 2 bytes and in the same program being implemented in Windows (Win32), int takes 4 bytes. The size of integer and its range is shown below as:
On 16 bit operating system machine: 2 bytes with range -32768 to 23767 |
On 32 bit operating system machine: 4 bytes with range -2,147,483,648 to 2,147,483,647 |
Other Integer Types
C programming language offers three keywords to modify the basic integer type, i.e. short, long and unsigned. These are called integer modifiers. The following points are to be kept in mind regarding these modifiers:
- The type short int or simply, short, may use less storage than int, thus saving space when only small numbers are needed. Like int, short is a signed type.
- The type long int or simply, long, may use more storage than int, thus, enabling to express larger integer values. Like int, long is a signed type.
- The type long long int or simply, long long, may use more storage than long, thus enabling to express even larger integer values. Like int, long long is a signed type.
- The type unsigned int or simply, unsigned, is used for variables that have only non-negative values. This type shifts the range of numbers that can be stored. For example, a 16 bit unsigned int allows a range from 0 to 65535 in value instead of the values from -32768 to 32767. The bit used to indicate the sign of signed numbers now becomes another binary digit, allowing the larger number.
- The keyword signed can be used with any of the signed types to make your intent explicit. For example, short, short int, signed short and signed short int are all names for the same type.
The following table summarizes the integer data type sizes in bits for different operating system environments and ANSI C minimum recommended. The MS-DOS supports the minimum ANSI C size.
Type | Linux | Windows (Win32) | ASCI C Minimum |
char | 8 | 8 | 8 |
int | 32 | 32 | 16 |
short | 16 | 16 | 16 |
long | 32 | 32 | 32 |
long long | 64 | 64 | 64 |