C ++中的字符串文字的类型是什么? [英] What is the type of a string literal in C++?

查看:126
本文介绍了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 is isarray of 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 ++中的字符串文字的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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