当在多个字符上使用时,单引号在C ++中做什么? [英] What do single quotes do in C++ when used on multiple characters?

查看:131
本文介绍了当在多个字符上使用时,单引号在C ++中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇这段代码:

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

给我输出 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆