I was reading a C programming book, and I have just passed by a paragraph who states the following: "character constants, like 'F', are ints, not chars, which explains why sizeof 'F' is equal to sizeof (int)".
But I didn't believed this, so I decided to test for my self and the results where:
printf("%ld", sizeof('F')); //output 4;
But if we do:
char a = 'F';
printf("%ld", sizeof(a)); //output 1;
So my question is, what's going on under the hood? Why is 'F' handled by the compiler as an int, while it could help be handled as a char, which occupied less memory?
I have a guess, since 'F' is a constant and is typically stored in a register, it would be irrelevant to handle it has a char|int or long... Can somebody confirm my assumption or explain me why this happens?