title: string reverse in C++
body: <p>I found this piece of code on the site, it seems the author is long gone, anyway, I'm having hard time understanding the actual swap and how the reverse occurs:</p>
  
  <pre><code>void strrev2(char *str)
  {
          if( str == NULL )
                  return;
  
          char *end_ptr = &amp;str[strlen(str) - 1];
          char temp;
          while( end_ptr &gt; str )
          {
                  temp = *str;
                  *str++ = *end_ptr;
                  *end_ptr-- = temp;
          }
  }
  </code></pre>
  
  <p>let's say you feed it word "testing"</p>
  
  <p>First iteration:</p>
  
  <pre><code>*end_ptr = 'g';
  
  temp = 't'
  *str = 'g' // is it first assigned and then incremented to point to the next location?
  *end_ptr = 't' // is it first assigned and then decremented to point to the previous location?
  </code></pre>
  
  <p>What happens on the second iteration? I'm having hard time because I thought that on this line:   </p>
  
  <pre><code>char *end_ptr = &amp;str[strlen(str) - 1];
  </code></pre>
  
  <p><code>end_ptr</code> will only contain address of one letter, so how can <code>*end_ptr</code> work?</p>
  
  <p>Anyway, if someone can explain this to me in some graphical way..
  Thanks.</p>