What do single quotes do in C++ when used on multiple characters?

lucidreality picture lucidreality · Sep 18, 2011 · Viewed 18.6k times · Source

I'm curious about this code:

cout << 'test'; // Note the single quotes.

gives me an output of 1952805748.

My question: Is the output an address in memory or something?

Answer

K-ballo picture K-ballo · Sep 18, 2011

It's a multi-character literal. 1952805748 is 0x74657374, which decomposes as

0x74 -> 't'
0x65 -> 'e'
0x73 -> 's'
0x74 -> 't'

Edit:

C++ standard, §2.14.3/1 - Character literals

(...) An ordinary character literal that contains more than one c-char is a multicharacter literal . A multicharacter literal has type int and implementation-defined value.