Character Data Type in C

The Character data type is used to specify a variable that will contain characters from ASCII table like ‘A’, ‘%’, and so on. The keyword used by C language to specify some variable as character is char. The width of memory allocated to a character variable is 8 bits. The char variable stores the character internally as an integer which corresponds to its equivalent ASCII code. This means a direct assignment of some valid 8-bit positive integer is also possible. However, it will be interpreted as its equivalent ASCII character in character manipulating functions. Consequently, negative integer values are also possible though they do not have any representation in ASCII code. By default, a char variable is signed. This means, only 7-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 character codes that can be stored in character variable can have a minimum value of -128 and a maximum value of 127 (-2 7 to +2 7 -1). The highest positive value is one less than the highest negative value, because 0 is treated as positive integer. Furthermore, C also provides keywords signed and unsigned to be prepended to the char keyword to further qualify the variable so created as one that will hold signed or unsigned integer values respectively. Table – 1 shows various variants of character data type along with their width and range.

Screenshot from 2020-07-10 18-16-21

Table -1: Various forms of Character data type in C