title: C++ for loop/char pointer "hack"
body: <p>I have a small piece of code which does something funny, but I can't figure out how it does it.</p>
  
  <pre><code>int main(int argc, const char * argv[])
  {
      char text[] = "object";
      for(char *ptr = &amp;text[0]; *ptr != '\0'; ptr+=2) 
      {   
          cout &lt;&lt; ptr &lt;&lt; endl;
          ptr--;
      }
      return 0;
  }
  </code></pre>
  
  <p>What's happening is that it goes from [1], [2], [3] and so on, to the end of the string every time, printing the content out. I cant understand how it does that, as pointer never gets dereferenced, but right letters seems to get printed. I would assume that instead of the letters of the string, the pointer values would print as weird characters thats all, yet, that's not what happens. </p>