c++ - С++ 中的字符串文字是在静态内存中创建的吗?

标签 c++ string char

C++ 中的字符串字面量是否在静态内存中创建并仅在程序退出时销毁?

最佳答案

是的,字符串字面量在程序的整个过程中都有效,即使在静态对象的销毁期间也是如此。

标准中的 2.13.4/1 说

An ordinary string literal has type "array of n const char" and static storage duration.

标准在 3.7.1/1 中提到“静态存储持续时间”:

The storage for these objects shall last for the duration of the program.

关于c++ - С++ 中的字符串文字是在静态内存中创建的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/349025/

相关文章:

c++ - 如何在 C++ 中对字符串变量应用计数出现次数的概念

c++ - 为什么模板只能在头文件中实现?

java - H2数据库连接字符串

string - 子串的VB6索引

计算二维字符数组中单词的出现次数

c++在win32学校应用程序上构建错误

C++ 将 2d 数组(由 uniqe_ptr 引用)合并到 3d 数组中

c++ - 如何在 *.cpp 文件中实现静态类成员函数?

python - 正则表达式拆分的 maxsplit 功能

c - 使用消息和 msgsnd 时在 C 中提取单个字符