Possible Duplicate:
Size of character ('a') in C/C++
Can someone explain why in C sizeof(char) = 1 and sizeof(name[0]) = 1 but sizeof('a') = 4?
name[0] in this case would be char name[1] = {'a'};
I’ve tried to read through C’s documentation to get this but I simply don’t get it! if sizeof('a') and sizeof(name[0]) were both 4 I would get it, if they were both 1 that would make sense… but I don’t get the discrepancy!
In C, character literals such as
'a'have typeint, and hencesizeof('a')is equal tosizeof(int).In C++, character literals have type
char, and thussizeof('a')is equal tosizeof(char).References:
C99 Standard: 6.4.4.4 Character constants
Para 2:
C++03 Standard: 2.13.2 Character literals
Para 1: