c - 初始化char数组的不同方式

标签 c arrays string initialization

用大括号和不带大括号初始化 char 数组有什么区别?

char arr[] = {"string"};

char arr[] = "string";

最佳答案

没有区别。 C99 直接解决了这个问题,6.7.8 初始化:

  1. An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.

(强调我的。)

关于c - 初始化char数组的不同方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52232560/

相关文章:

c - 将相同的函数应用于C中数组中的每个元素

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

r - 使用 `apply` 将字符串修改为 `tolower`

python - 使用 python 正则表达式删除除组合为字符串的数字之外的所有数字

c++ - 获取对 function_name 的 undefined reference

c - 从 C 中的文件读取后,来自标准输入的垃圾字符

javascript - 如何编写一个接受 2 个字符串的函数,并将它们添加到相应数组的开头

string - 如何编写一个接受字符串并返回最长有效子字符串的方法

C - 断言失败错误

c - 如何在 Linux 中以编程方式获取目录的大小?