Possible Duplicate:
Why are C character literals ints instead of chars?
folks,
I tried to print out the size of char in C. With the following code, I got the result output as
int, 4
char, 1
char?, 4
Why is the last one not the same as the 2nd one? Thanks.
#include <stdio.h>
main()
{
int a = 2;
char b = '2';
printf("int, %d\n",sizeof(a));
printf("char, %d\n",sizeof(b));
printf("char?, %d\n",sizeof('a'));
}
In C, a character constant like
'a'has typeint.This is different from C++ and Java, where a character constant like
'a'has typechar,