title: Run through a structure and print all the values?
body: <p>I have a pointer to a structure and I'd like to fetch all of its members by trial and error. I'm trying to run through the structure by incrementing the pointer by one and derefencing it. It should return a correct value from the structure (every <code>i*sizeof(int)</code> time) but it doesn't. </p>
  
  <p><strong>What am I doing wrong?</strong></p>
  
  <pre><code>fn (mach_msg_header_t *InHeadP, mach_msg_header_t *OutHeadP)
  {
  
      /*
       assume that all struct members are int types
  
       typedef    struct 
       {
       mach_msg_bits_t    msgh_bits;
       mach_msg_size_t    msgh_size;
       mach_port_t        msgh_remote_port;
       mach_port_t        msgh_local_port;
       mach_msg_size_t    msgh_reserved;
       mach_msg_id_t      msgh_id;
       } mach_msg_header_t;
  
       size of the struct is 24.
       */
  
      printf("ID: %d \n",InHeadP-&gt;msgh_id); //prints 'ID: 1337'
      printf("Ptr: %p\n",InHeadP);
  
      for (int i = 0; i &lt;= 24; i++)
      {
          int deref = *((int*)(InHeadP+i));
          printf("InHeadP[%d]=%d\n",i,deref);
              //no sign of 1337 anywhere
  
      }
  }
  </code></pre>
  
  <p><em>P.S. I know that I shouldn't be doing that, but this is only for testing purposes.</em></p>