Integer Data Type in C

The Integer data type is used to specify a variable that will contain only integer values, i.e. any positive or negative number without fractional part. The keyword used by C language to specify some variable as integer is int. The width of memory allocated to an integer variable is generally one word. However, the word length varies from machine to machine. For a 16-bit machine, the word length is 16-bits. Also, Turbo C 3.0 is a 16-bit compiler which means the size of an integer variable will be 2 bytes. Please note that because we will be implementing all our programs on TC3.0, so we will consider a 16-bit machine for here onwards. Furthermore, to represent both positive and negative integers, one bit is reserved for sign. This means, only 15-bits are used to store the magnitude of data while the remaining one bit is used to store the sign of the data. Therefore, the range of integers that can be stored in an integer variable can have a minimum value of -32768 and a maximum value of 32767 (-2 15 to +2 15 -1). The highest positive value is one less than the highest negative value, because 0 is treated as positive integer.

By default int specifies the variable as signed integer variable with width equal to machine word. However, C also provides certain qualifiers to further qualify the integer data type. These qualifiers can be classified into 2 classes.

1. One class specifies whether the integer variable will hold signed numbers (both positive and negative) or unsigned numbers (only
positive numbers). The keyword signed if prepended to int keyword specifies that the integer variable will hold both positive and negative numbers. Indeed, by default int is signed. As mentioned earlier, the range of such a variable will be -32786 to +32767. If the keyword unsigned is prepended to int keyword, the variable so declared will only hold positive integers. This means no sign bit will be reserved and full word (16-bit in our case) will contain the magnitude. This means the variable can contain a range of integers with a minimum value of 0 to a maximum value of 65535 (0 to 2 16 -1).

2. The other class specifies the size of integer variable. By default its size is one word (16-bits in our case). However, if short keyword is prepended to int keyword then the variable occupies only 8 bits. In contrast, if long keyword is prepended to int keyword then the variable occupies double word (32-bits in our case).

It should be noted that both classes of qualifiers can be used simultaneously. Table – 1 shows various variants of integer data type along with their width and range on 16-bit machine.

Screenshot from 2020-07-10 18-07-34

Screenshot from 2020-07-10 18-08-04

Table – 1: Various forms of Integer data type in C