当在多个字符上使用单引号时,C++ 中的单引号有什么作用? [英] What do single quotes do in C++ when used on multiple characters?
本文介绍了当在多个字符上使用单引号时,C++ 中的单引号有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对这段代码很好奇:
cout << 'test'; // Note the single quotes.
给我一个 1952805748
的输出.
gives me an output of 1952805748
.
我的问题:输出是内存中的地址还是什么?
My question: Is the output an address in memory or something?
推荐答案
这是一个多字符文字.1952805748
是 0x74657374
,分解为
It's a multi-character literal. 1952805748
is 0x74657374
, which decomposes as
0x74 -> 't'
0x65 -> 'e'
0x73 -> 's'
0x74 -> 't'
C++ 标准,§2.14.3/1 - 字符字面量
(...) 包含多个的普通字符字面量一个 c-char 是一个多字符文字.多字符文字具有 int 类型和实现定义价值.
(...) 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++ 中的单引号有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文