I am currently studying C language. I was studying Datatypes, please tell me, why characters are called integral constants?
CodePudding user response:
Because they are represented with non-modifiable integer values.
For ASCII characters, for example, these values range between 0 and 255.
CodePudding user response:
You may perform integer operations with objects of the type char
. For example you may decrease or increase a value stored in an object of the type char, or add or subtract a value.
For example if an object of the type char contains a symbol that represents a digit as for example
char c = '5';
then you can get the digit as a number the following way
int digit = c - '0';
The variable digit will contain the number 5
.
Pay attention to that the type char
can behave either as the type signed char
or unsigned char
dependent on compiler options.
In C opposite to C integer character constants have the type int
.