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

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

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?

ベストアンサー1

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.

おすすめ記事