Rn2dy
Rn2dy

Reputation: 4190

Does inclusion of {} matter in C string initialization?

What is the difference between the following?

char input[] = {"abc"};

and

char input[] = "abc";

Upvotes: 14

Views: 262

Answers (1)

ouah
ouah

Reputation: 145899

Both forms are equivalent and permitted.

char input[] = "abc";

or

char input[] = {"abc"};

Here is the relevant paragraph from the C Standard:

(C99, 6.7.8p14): "An array of character type may be initialized by a character string literal, optionally enclosed in braces"

Upvotes: 23

Related Questions