title: char * string = "Hello"; memory address space
body: <p>This board seems filled with these type of questions and I did go through a few of them, but I still am confused regarding the difference between those two:</p>
  
  <pre><code>char string[] = "Hello"; 
  char * string2 = "hello";
  </code></pre>
  
  <p>Now, </p>
  
  <pre><code>char string[] = "Hello"; 
  </code></pre>
  
  <p>... is an array and is allocated 6 consecutive memory address spaces where the characters are stored, including \0 at the end.</p>
  
  <p><strong>%p</strong> of <strong>&amp;string</strong> shows memory address 0x7fffbcabce90. <strong>%p</strong> of <strong>string</strong> shows the same memory address 0x7fffbcabce90. <strong>%p</strong> of <strong>string[1]</strong> shows 0x7fffbcabce90 + typeof(char), so 0x7fffbcabce91. etc.</p>
  
  <pre><code>char * string2 = "hello";
  </code></pre>
  
  <p>... is a pointer to char type and it points to memory address of the first character of the string (h).</p>
  
  <p><strong>%p</strong> of <strong>&amp;string2</strong> shows memory address 0x7fffbcabce88. <strong>%p</strong> of <strong>string2</strong> shows a different memory address of 0x400ca8. <strong>%p</strong> of <strong>string2[1]</strong> shows 0x400ca8 + sizeof(char), so 0x400ca9.</p>
  
  <p><strong><em>My questions are</em>: what is this memory address range (0x400000)? Is it the reason why I can't modify the string characters like so?:</strong></p>
  
  <pre><code>string[1] = 'c';   //that works
  string2[1] = 'c';  //not working
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>Edit: typo (%string2 => &amp;string2)</p>
  
  <p>Edit2: As was explained to me, the keyword is string <strong>literal</strong>. </p>
  
  <pre><code>char * string2[] = "Hello"; 
  </code></pre>
  
  <p>... is a pointer to a string literal. Here's a thread where R Samuel Klatchko explains where are stored literals in memory:</p>
  
  <p><a href="https://stackoverflow.com/questions/2589949/c-string-literals-where-do-they-go">String literals: Where do they go?</a></p>