c++ - 空终止字符串

标签 c++

下列哪些是以null结尾的字符串?

char *str1 = "This is a string.";
char *str2 = "This is a string.\0";
char str3[] = "This is a string.";
const char *str4 = "This is a string.";
const char *str5 = "This is a string.\0";
const char str6[] = "This is a string.";

最佳答案

  • All : 一个字符串字面量是一个以空结尾的字符串
  • str2str5 具有双重空终止字符串的特殊性

还有:

  • char *str1 应该是 const char *str1
  • char *str2 应该是 const char *str2

关于c++ - 空终止字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4395991/

相关文章:

c++ - 有没有办法从一组图像中识别出不太相似的区域?

c++ - 不能分配给这个

c++ - XSD 方案语法和 gSoap

c++ - 转换层次结构 - 将 parent 的方向应用于其 child

C++: "T a = b"-- 复制构造函数还是赋值运算符?

c++ - 查找以特定字符串开头的文件

c++ - 为什么我得到 : "Attempting to reference a deleted function" error after adding a vector with unique pointers to my header file?

c++ - 与 C++ 应用程序的轻量级网络服务器通信

c++ - 当我调用形状的构造函数 "shape() "时 SFML 不绘制形状

C++ 有故障?