title: String literals: pointer vs. char array
body: <p>In this statement:</p>
  
  <pre><code>char *a = "string1"
  </code></pre>
  
  <p>What exactly is string literal? Is it <code>string1</code>? Because this thread <a href="https://stackoverflow.com/questions/2245664/string-literals-in-c">What is the type of string literals in C and C++?</a> says something different.</p>
  
  <p>Up to my knowledge</p>
  
  <pre><code>int main()
  {
      char *a = "string1"; //is a string- literals allocated memory in read-only section.
      char b[] = "string2"; //is a array char where memory will be allocated in stack.
  
      a[0] = 'X'; //Not allowed. It is an undefined Behaviour. For me, it Seg Faults. 
      b[0] = 'Y'; //Valid. 
  
      return 0;
  } 
  </code></pre>
  
  <p><strong>Please add some details other than above mentioned points. Thanks.</strong></p>
  
  <p><strong>Debug Output Showing error in</strong> <code>a[0] = 'Y';</code></p>
  
  <pre><code>Reading symbols from /home/jay/Desktop/MI/chararr/a.out...done.
  (gdb) b main
  Breakpoint 1 at 0x40056c: file ddd.c, line 4.
  (gdb) r
  Starting program: /home/jay/Desktop/MI/chararr/a.out 
  
  Breakpoint 1, main () at ddd.c:4
  4   {
  (gdb) n
  6   char *a = "string1";
  (gdb) n
  7   char b[] = "string2";
  (gdb) 
  9   a[0] = 'Y';
  (gdb) 
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0000000000400595 in main () at ddd.c:9
  </code></pre>