In your code-snippet you defined a local array (explicit count given as 4 elements) which contains pointers to const string-literals.
Let's check the assembly of your code, if you want to go a level deeper (created with x86 gcc 4.9.2)
.LC0:
.string "Dany"
.LC1:
.string "Emily"
.LC2:
.string "Eric"
.LC3:
.string "Alex"
main:
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-32], OFFSET FLAT:.LC0
mov QWORD PTR [rbp-24], OFFSET FLAT:.LC1
mov QWORD PTR [rbp-16], OFFSET FLAT:.LC2
mov QWORD PTR [rbp-8], OFFSET FLAT:.LC3
mov eax, 0
pop rbp
ret
Each binary/executable is organized in different segments [1] page 15. One part is for global variables, one is for the code, and another one is for read-only data (.rodata section), ... . As you can see, the assembly contains the 4 defined string-literals which go in the read-only section (see label .LC(0-9)
)
FYI: String-literals (actually everything) in the read-only section are const and must be declared as const
. Trying to modify this section leads to undefined behavior.
const char* names[4]= {"Dany", "Emily", "Eric", "Alex"};