title: Segmentation fault occurring when modifying a string using pointers?
body: <h2>Context</h2>
  
  <p>I'm learning C, and I'm trying to reverse a string in place using pointers. (I know you can use an array; this is more about learning about pointers.)</p>
  
  <h2>Problem</h2>
  
  <p>I keep getting segmentation faults when trying to run the code below. <a href="https://en.wikipedia.org/wiki/GNU_Compiler_Collection" rel="nofollow noreferrer">GCC</a> seems not to like the <code>*end = *begin;</code> line. <strong><em>Why is that?</em></strong></p>
  
  <p>Especially since my code is nearly identical to <a href="https://stackoverflow.com/a/198275/140264">the non-evil C function already discussed in another question</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void my_strrev(char* begin){
      char temp;
      char* end;
      end = begin + strlen(begin) - 1;
  
      while(end&gt;begin){
          temp = *end;
          *end = *begin;
          *begin = temp;
          end--;
          begin++;
      }
  }
  
  main(){
      char *string = "foobar";
      my_strrev(string);
      printf("%s", string);
  }
  </code></pre>