我很好奇这段代码:
cout << 'test'; // Note the single quotes.
给我一个 1952805748
的输出。
我的问题:输出是内存中的地址还是什么?
最佳答案
这是一个多字 rune 字。 1952805748
为0x74657374
,分解为
0x74 -> 't'
0x65 -> 'e'
0x73 -> 's'
0x74 -> 't'
编辑:
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.
关于c++ - 单引号在 C++ 中用于多个字符时有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459939/