Possible Duplicate:
Why are C character literals ints instead of chars?
why sizeof('a') is 4 in C?
#include<stdio.h>
int main()
{
char ch;
fflush(stdin);
ch=getchar();
printf("ch= %d a=%d char=%d", sizeof(ch),sizeof('a'),sizeof(char));
}
I type in ‘a’ (without quotes) as input , and the output I got in my gcc version 4.5.1 is :
ch= 1 a=4 char=1
My question is :
If sizeof(c) is 1 , then how can sizeof('a') be 4 ?
On most of the systems ‘a’== 97, which ASCII value of the character ‘a’.
for e.g:
If you print the value of variable
cwith the option ‘%c’ you’ll see ‘a’ on the screen. for your question we can deducesizeof('a')assizeof(i)equable tosizeof(97);You should be able to find this in C standards document.