Unsolved Storage of const char* in memory layout
-
int main() { char * str = "Hello"; return 0; }
Hello All,
Can you please help me understand where content of str( i.e "Hello") is stored in memory layout in C/C++. -
When program is linked, typically literal string constats like your
"Hello"
are placed in read-only section of binary (e.g.,.rodata
for ELF). When program is executed, this read-only section is mapped into memory by OS.You can read more about ELF sections and their loading at https://wiki.osdev.org/ELF. Other binary formats used by modern OSes have their differences, but main concepts are quite similar.
-
Thank you @Konstantin-Tokarev .
Will look into the link provided by you.