Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "hello" and {"hello"}?

In C/C++, what's the difference between the following two line code:

char *str1="hello";  
char *str2={"hello"};  
like image 757
yejinxin Avatar asked Oct 05 '12 12:10

yejinxin


People also ask

Which is formal hi or hello?

Hi is equivalent to hello, but it is considered a little bit more informal in tone. In fact, it was recorded a lot earlier than hello. Hi developed from the Middle English hy, similar to hey and ha.

What's the difference between hello and hi?

HELLO is a word you use to show that you are happy to see or meet someone. For example: "Hello, my name is Tom and I'm the new kid." HI has the same meaning, but it is more informal. For example: "Hi John!


2 Answers

Per the 2011 C standard, clause 6.7.9 Initialization, paragraph 11: “The initializer for a scalar shall be a single expression, optionally enclosed in braces…”

That is it. There is no semantic difference; the braces simply may be present or may be absent, with no change to the meaning.

like image 172
Eric Postpischil Avatar answered Sep 17 '22 19:09

Eric Postpischil


Style only in this case. They both result in the same thing, and they're both bad form. You should have used const char * str1="hello";.

like image 36
David Hammen Avatar answered Sep 17 '22 19:09

David Hammen