

Character literal is not a character in C  - slashdotaccount
http://arjunsreedharan.org/post/78628168199/character-literal-is-not-a-character-in-c

======
adamnemecek
This is one of the few examples of code that is valid in both C and C++ but
that produces different results (in C++ the size would be 1).

------
gregjor
No mystery. C's char type is a single byte, an integer type of (usually) 8
bits, though the actual size is platform-dependent. A char may be signed or
unsigned, like the other integer types (short, int, long).

The value of a char is the ASCII code for the character, so 'a' is stored as
the integer 97.

This is documented in "The C Programming Language" on pages 35-36.

C does not have a string type. By convention a string is an array of char with
a null (0) byte at the end.

C++ follows the same conventions for char and arrays of char, but implements
"real" strings with more string-like behavior.

------
kahirsch
In fact, you can have multi-character character constants, e.g.

    
    
        printf("sizeof('abcd') %d\n", sizeof('abcd'));  
        printf("'abcd' = %d\n", 'abcd');
    

produces

    
    
        sizeof('abcd') 4  
        'abcd' = 1633837924

------
J_Darnley
All integer constants "start" as type int. The message isn't about what size
your value is but the fact that you are comparing a pointer with an integer.
Cast to a char and you still get the same message

