char a[] = "aesdf"; char a[] = {'a','e','s','d','f','\0'};
These two lines of code have the same effect. The compiler can choose to implement them the same way, otherwise it can choose them differently.
From the point of view of a programmer writing code in C, this does not really matter. You can use them and make sure that you end up with a six-element array of char initialized with the specified content.
Will "aesdf" exist for the entire duration of the executable file?
Semantically, yes. String literals are char arrays that have a static storage duration. An object with static memory has a program lifespan: it is initialized before the program starts and exists until the program terminates.
However, this does not make any difference in your program. This string literal is used to initialize array a . Since you are not getting a pointer to the actual string literal, it does not matter what its actual lifetime is for this string literal or how it is actually stored. The compiler can do whatever it sees fit as long as array a is properly initialized.
source share