I’d like to know, how to calculate integer values of strings in single quotes ' '.
My sample code is:
#include <stdio.h>
int main()
{
int c = 'aA';
int d = 'Aa';
printf( "%d %d" , c, d);
return 0;
}
And the output is:
24897 16737
What are those numbers? Is there any formula to calculate them ?
These are:
not strings!
multibyte integers, of which the value is implementation-defined, but it is usually calculated using this formula:
integer value of 1st character multiplied by (2 << CHAR_BITS) + integer value of 2nd characterSo, assuming your C locale uses ASCII and you have 8-bit bytes,
'aA'becomeswhich is 24897.
Multicharacter literals are of type
int.