title: Unhandled exception at 0x003860EF in Chapter1.exe: 0xC0000005: Access violation writing location 0x0038EE7C
body: <p>I am writing a very simple test program to swap all characters in a string pointed by char*. However, I got a really strange exception from Visual C++.</p>
  
  <p>My code will be pasted below and Chapter1 is the name of the project.</p>
  
  <p>Thanks everyone in advance and please feel free to post below to ask for any further question.</p>
  
  <p>Question2.h</p>
  
  <pre><code>#ifndef _QUESTION2_H_
  #define _QUESTION2_H_
  
  namespace Q2
  {
      void swap(char *begin, char *end);
  
      void reverse(char *str);
  
      void run();
  }
  
  #endif
  </code></pre>
  
  <p>Question2.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include "Question2.h"
  
  using namespace std;
  
  namespace Q2
  {
  void swap(char *begin, char *end)
  {
      char tmp = *begin;
      *begin = *end;
      *end = tmp;
  }
  
  void reverse(char *str)
  {
      char *begin = str;
      char *end = str;
  
          while(*end != NULL)
          end++;
      end--;
  
          for(; begin &lt; end; begin++, end--)
          swap(begin, end);
  }
  
  void run()
  {
      char *str1 = "hello";
  
      reverse(str1);
  
      cout &lt;&lt; str1 &lt;&lt; endl;
  
      return;
      }
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include "Question2.h"
  
  int main()
  {
      Q2::run();
  
      return 0;
  }
  </code></pre>