Have you ever tried to open some executabe file with a text editor? It just looks like garbage, but in the middle of the garbage you can see some readable lines. These are all lettering strings defined in your program.
printf("my literal text"); char * c = "another literal text";
If your program contains the above code, you can find my literal text and another literal text in the binary code of the program (in fact, it depends on the details of the binary format, but it often works). If you are a Linux / Unix user, you can also use the strings command to do this.
By the way, if you write the code above, C ++ compilers will give a warning (g ++ say: warning: deprecated conversion from string constant to 'char*' , because such strings are not of type char * , but const char [] (const char array), which decays to const char * when assigned to a pointer.
This also applies to C compilers, but the above error is so common that this warning is usually turned off. gcc does not even include in -Wall, you must explicitly enable it through -Wwrite-strings . Warning warning: initialization discards 'const' qualifier from pointer target type .
It just reminds you that you are theoretically not allowed to change literal texts with pointers.
An executable file can load such lines in read-only parts in the memory of a data segment. If you try to change the contents of a string, this may result in a memory error. Also, the compiler is allowed to optimize literal text storage, for example, by merging identical strings. The pointer simply contains an address in memory (read-only) where literals will be loaded.
On the other hand,
char c[] = "string"; is a simple syntactic sugar for char c[7] = {'s', 't', 'r', 'i', 'n', 'g', 0}; If you execute sizeof(c) in your code, it will be 7 bytes (the size of the array, not the size of the pointer). This is an array on the stack with an initializer. Internally, the compiler can do it anyway when it likes to initialize an array. It can be character constants loaded one by one into the array, or it can include memcpy of some hidden string literal. The fact is that you do not have the opportunity to tell the difference with your program and find out where the data came from. Only the result matters.
By the way, a bit confusing thing is that if you define a function parameter of type char c[] , it will not be an array, but an alternative syntax for char * c .