title: How is C able to compare and increment an array of structs directly in a for loop?
body: <p>I am a newcomer to the world of C. I am self-teaching and would appreciate some help with a couple of questions.</p>
  
  <p>This program is a simplified variation on one written in <a href="http://publications.gbdirect.co.uk/c_book/chapter6/structures.html#section-1" rel="nofollow">this example</a> to demonstrate the use of pointers with arrays of structs. The things I'm having trouble getting my head around are:</p>
  
  <ol>
  <li>How the array is incremented in the first for loop. The <code>++</code> operator is used directly on the array of structs whereas I would have expected the need to do something more like <code>in_p[i]</code> inside the loop (with i being an int that get incremented). </li>
  <li>The way that the comparison is being made in this loop. I didn't think that <code>in_p &lt; &amp;ar[ARSIZE]</code> would be possible since both are of type <code>struct wp_char</code>. What is actually being compared here? </li>
  </ol>
  
  <p>Both the example in the book and my example compile and run.</p>
  
  <p>Thank you.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define ARSIZE 5
  
  struct wp_char{
        char wp_cval;
        short wp_font;
        short wp_psize;
  }ar[ARSIZE];
  
  void infun(struct wp_char *, char cval, int font, int psize);
  
  int main(void)
  {
      struct wp_char wp_tmp, *lo_indx, *hi_indx, *in_p;
      char c[] = {'a','b','c','d','e'};
      int i1[] = {2,3,4,5,6};
      int i2[] = {7,8,9,10,11};
      int i = 0;
  
      for(in_p = ar; in_p &lt; &amp;ar[ARSIZE]; in_p++){
          infun(in_p, c[i], i1[i], i2[i]);
          i++;
      }
  
      int j;
  
      for(j=0;j&lt;ARSIZE;j++)
      {
          printf("%c\n",c[j]);
          printf("%d\n",i1[j]);
          printf("%d\n",i2[j]);
          puts("\n");
      }
  
      exit(0);
  }
  
  void infun( struct wp_char *inp, char cval, int font, int psize)
  {
  `
        inp-&gt;wp_cval = cval;
        inp-&gt;wp_font = font;
        inp-&gt;wp_psize = psize;
  
        return;
  }
  </code></pre>