principlecppCritical
Single quotes vs. double quotes in C or C++
Viewed 0 times
doublesinglequotes
Problem
When should I use single quotes and double quotes in C or C++ programming?
Solution
In C and in C++ single quotes identify a single character, while double quotes create a string literal.
In C++ the type of a character literal is
'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.Context
Stack Overflow Q#3683602, score: 361
Revisions (0)
No revisions yet.