title: Looping through array using pointers
body: <p>The following program in C++ prints more output than I expected. Can anyone explain why this has happened? The program attempts to use pointers to loop through the integer array, printing each value along the way.</p>
  
  <pre><code>#include &lt;cstdio&gt;
  using namespace std;
  
  int main(int argc, char **argv) {
      puts("hi");
      int ia[5] = {1,2,3,4,5};
      for (int *p = ia; *p; ++p) {
          printf("Char is: %d\n", *p);
      }
      return 0;
  }
  
  /*
   hi
   Char is: 1
   Char is: 2
   Char is: 3
   Char is: 4
   Char is: 5
   Char is: 32767
   Char is: -811990796
   Char is: -133728064
   Char is: 1606416320
   Char is: 32767
   Char is: -1052593579
   Char is: 32767
   Program ended with exit code: 0
  */
  </code></pre>