Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Storage of const char* in memory layout
Forum Updated to NodeBB v4.3 + New Features

Storage of const char* in memory layout

Scheduled Pinned Locked Moved Unsolved C++ Gurus
3 Posts 2 Posters 424 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vinoth Rajendran4
    wrote on last edited by
    #1
    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++.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by Konstantin Tokarev
      #2

      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.

      V 1 Reply Last reply
      5
      • K Konstantin Tokarev

        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.

        V Offline
        V Offline
        Vinoth Rajendran4
        wrote on last edited by
        #3

        Thank you @Konstantin-Tokarev .

        Will look into the link provided by you.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved