title: Why modifying a string with different ways have different behaviors?
body: <p>Why these two code snippets have different behaviors</p>
  
  <pre><code>char p[] = "hello";
  p[0] = 'W'; //works fine
  </code></pre>
  
  <p>While this gives a <code>segmentation fault</code></p>
  
  <pre><code>char *ptr = "hello"; 
  ptr[0] = 'W'; // undefined behavior
  </code></pre>
  
  <p>What is the difference between both codes,why i am unable to modify the string using pointer?</p>