7
A
回答
10
每2011 C标准中第6.7 .9初始化,第11段:“标量的初始值应该是一个单一的表达式,可选地用大括号括起来......”
就是这样。没有语义上的差异;大括号可以简单地存在或可以不存在,而不改变含义。
6
-1
由于字符串是一个字符数组,因此数组和字符串之间没有区别。
2
请参阅https://stackoverflow.com/a/3462768/153225。
大括号是多余的。
生成汇编形成具有“GCC -S”下面的代码证实它们生成完全一样的东西(在每种情况下一个稍微不同的常数):
#include <iostream>
using namespace std;
void test1() {
const char *str1="hello1";
cout << str1 << endl;
}
void test2() {
const char *str2={"hello2"};
cout << str2 << endl;
}
int main() {
test1();
test2();
}
相关问题
- 1. “hello”.length和“hello”.length是什么区别?
- 2. “http:// localhost/app/hello”和“http:// localhost/app/hello /”有什么区别?
- 3. objective-c @“hello”和“hello”之间的区别?
- 4. scala中的“Hello”foreach(x = x * _.toLong)和“Hello”foreach(x * = _.toLong)有什么区别?
- 5. 使用双引号时,{$ hello},$ {hello}和$ hello有什么不同?
- 6. String s1 =“Hello”和String s1 = new String(“Hello”)之间的区别是什么?
- 7. 文件名中的hello /和hello之间的区别,URI
- 8. out.println(“<html> Hello World</html>”)和out.println(“Hello World”)之间的区别
- 9. alias hello ='echo Hello' - 为什么重启后不工作?
- 10. Rails将'Hello&'保存为'Hello &'为什么?
- 11. 为什么我的本地git标签从“hello”到“hello-1-48281”
- 12. Hello World和V8
- 13. 为什么strcpy(strerror(errno),“Hello”)没有复制“Hello”,而是{ptr = strerror(errno); strcpy(ptr,“Hello”);}呢?
- 14. `string s(“hello”);```string s =“hello”;`
- 15. python print“hello world”vs“hello world”
- 16. 亚太地区的Hello World
- 17. Angular.js Hello World 1.2.0和1.4.7之间的区别
- 18. 找到次数字符串“hello hello”的次数的正则表达式出现在字符串“hello hello hello”中
- 19. 有什么区别`和$(Bash中有什么区别?
- 20. Python的新手的hello world(为什么???)
- 21. SPDY“Hello world”会是什么样子?
- 22. 什么是画一个Hello World Java中
- 23. 并发程序的“Hello World”是什么?
- 24. 为什么结果是Hello World?
- 25. 为什么“Hello”.foldLeft(1)(_。toLong * _.toLong)出错?
- 26. /ell/==='Hello'在Ruby中为true。为什么?
- 27. 为什么不显示消息“Hello world!”?
- 28. Javascript InfoVis Toolkit的'Hello,World'是什么?
- 29. 有什么区别? :和||
- 30. &&和||有什么区别?
没有区别。它们都破坏了编译 –
@BЈовић至少在C++中,但不在C中(谁知道*“C/C++”*是什么)。 –
@ChristianRau - 我确切地知道“C/C++”是什么意思,我怀疑你也这么做。 –