When I ran this program it gave an output of
1, 4, 4
Why does sizeof('A') gives 4 bytes? Is 'A' treated as integer? If so, then why?
#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
Moreover, when I replace
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
with,
printf("%d, %d, %d", sizeof(ch), sizeof("A"), sizeof(3.14f));
It gives the output
1, 2, 4
which is even more confounding.
P.S.: I used compileonline.com to test this code.