Because in C character constants, such as ‘a’ have the type int
.
There’s a C FAQ about this suject:
Perhaps surprisingly, character constants in C are of type int, so
sizeof(‘a’) is sizeof(int) (though this is another area where C++
differs).
More Related Contents:
- Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?
- size of character array and size of character pointer
- In C, why is sizeof(char) 1, when ‘a’ is an int?
- Removing digits and all punctuation except apostrophe from a string in C
- char c[]=”Albus”; printf(“%c”, c); [closed]
- Returning an array using C
- Why are C character literals ints instead of chars?
- What does sizeof(&array) return?
- How to do scanf for single char in C [duplicate]
- Why does a C-Array have a wrong sizeof() value when it’s passed to a function? [duplicate]
- newbie questions about malloc and sizeof
- Using sizeof with a dynamically allocated array
- Get a substring of a char* [duplicate]
- Determine if char is a num or letter
- Why does strchr take an int for the char to be found?
- No compiler error when fixed size char array is initialized without enough room for null terminator
- How can I print the result of sizeof() at compile time in C?
- C char array initialization: what happens if there are less characters in the string literal than the array size?
- Why do I get a warning every time I use malloc?
- Does C have a string type? [closed]
- sizeof single struct member in C
- Implementation of sizeof operator
- Reliably determine the number of elements in an array
- assigning more than one character in char
- C -> sizeof string is always 8
- Size of pid_t, uid_t, gid_t on Linux
- Get index of substring
- Reading newline from previous input when reading from keyboard with scanf()
- Why are compound literals in C modifiable
- How many chars can be in a char array?