Single quotes vs. double quotes in C or C++

Vishwanath Dalvi picture Vishwanath Dalvi · Sep 10, 2010 · Viewed 148.5k times · Source

When should I use single quotes and double quotes in C or C++ programming?

Answer

David Rodríguez - dribeas picture David Rodríguez - dribeas · Sep 10, 2010

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.