我是 C 编程的初学者,我无法弄清楚这两个表达式(带和不带花括号)之间有什么区别,如下所示。
char s1[] = {"The course of true love never did run smooth"};
char s1[] = "The course of true love never did run smooth";
我尝试使用进行测试
printf("%c", s1[0]), and
printf("%s", s1)
两者都给了我相同的答案。
最佳答案
没有区别,大括号是可选的。
从标准 6.7.9/14 开始:
An array of character type may be initialized by a character string literal or UTF−8 string literal, optionally enclosed in braces.
关于c - 在大括号和没有大括号的列表中声明的值有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68015444/