What is the type of a string literal in C++?(C ++中字符串文字的类型是什么?)
问题描述
例如,字符串文字Hello"的类型是什么,const char[6] 或 const char* ?
For example, what is the type of the string literal "Hello", const char[6] or const char* ?
推荐答案
字符串字面量 "Hello" 的类型是 "6 const char 的数组".
The type of the string literal "Hello" is "array of 6 const char".
普通字符串文字和 UTF-8 字符串文字也称为窄字符串文字.窄字符串文字的类型为数组 n const char",其中 n 是字符串的大小 [...]>
Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow string literal has type "array of n
const char", where n is the size of the string [...]
但是,它可以通过数组到指针的转换转换为 const char*.数组到指针的转换导致指向数组第一个元素的指针.
It can, however, be converted to a const char* by array-to-pointer conversion. Array-to-pointer conversion results in a pointer to the first element of the array.
这篇关于C ++中字符串文字的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C ++中字符串文字的类型是什么?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
