void main()
{
printf("%d\n",sizeof('1'));
}
Output : 4
void main()
{
char a='1';
printf("%d\n",sizeof(a));
}
Output : 1
Can somebody say why it is different ?
void main()
{
printf("%d\n",sizeof('1'));
}
Output : 4
void main()
{
char a='1';
printf("%d\n",sizeof(a));
}
Output : 1
Can somebody say why it is different ?
In C, character literals are of type int.
Note that this was changed in C++, in which character literals have the obvious type char.
In C, character literals are of type int, in another word, sizeof('1') is the same as sizeof(int).
While sizeof(a) is the real sizeof(char).