Please see the following statements:
char a[5]="jgkl"; // let's call this Statement A
char *b="jhdfjnfnsfnnkjdf"; // let's call this Statement B , and yes i know this is not an Array
char c[5]={'j','g','k','l','\0'}; // let's call this Statement C
Now, is there any difference between Statements A and C?
I mean both should be on Stack dont they? Only b will be at Static location.
So wouldn’t that make “jgkl” exist at the static location for the entire life of the program? Since it is supposed to be read-only/constant?
Please clarify.
If a[] is static then so is c[] – the two are equivalent, and neither is a string literal. The two could equally well be declared so that they were on the stack – it depends where and how they are declared, not the syntax used to specify their contents.