When should I use single quotes and double quotes in C or C++ programming?
In C and in C++ single quotes identify a single character, while double quotes create a string literal. 'a'
is a single a character literal, while "a"
is a string literal containing an 'a'
and a null terminator (that is a 2 char array).
In C++ the type of a character literal is char
, but note that in C, the type of a character literal is int
, that is sizeof 'a'
is 4 in an architecture where ints are 32bit (and CHAR_BIT is 8), while sizeof(char)
is 1 everywhere.