title: String in function parameter
body: <pre><code>int main()
  {
          char *x = "HelloWorld";
          char y[] = "HelloWorld";
  
          x[0] = 'Z';
          //y[0] = 'M';
  
          return 0;
  }
  </code></pre>
  
  <p>In the above program, <code>HelloWorld</code> will be in read-only section(i.e string table). <code>x</code> will be pointing to that read-only section, so trying to modify that values will be undefined behavior.</p>
  
  <p>But <code>y</code> will be allocated in stack and <code>HelloWorld</code> will be copied to that memory. so modifying y will works fine. <a href="https://stackoverflow.com/questions/12795850/string-literals-pointer-vs-char-array">String literals: pointer vs. char array</a></p>
  
  <p><strong>Here is my Question:</strong> </p>
  
  <p>In the following program, both <code>char *arr</code> and <code>char arr[]</code> causes segmentation fault if the content is modified. </p>
  
  <pre><code>void function(char arr[])
  //void function(char *arr)
  {
     arr[0] = 'X';
  }        
  int main()
  {
     function("MyString");    
     return 0;
  }
  </code></pre>
  
  <ol>
  <li>How it differs in the function parameter context?</li>
  <li>No memory will be allocated for function parameters?? <br/></li>
  </ol>
  
  <p>Please share your knowledge.</p>