title: Pointer expressions: **ptr++, *++*ptr and ++**ptr use
body: <p>I am trying my hands on a C pointer literature. In one of the illustrations, I encountered the following code.</p>
  
  <pre><code># include &lt;stdio.h&gt;
  
  int main()
  {
       static int a[]={0,1,2,3,4};
       static int *p[]={a, a+1, a+2, a+3, a+4};
  
       int **ptr;
  
       ptr =p;
  
       **ptr++;
       printf("%d %d %d\n", ptr-p, *ptr-a, **ptr);
  
       *++*ptr; 
       printf("%d %d %d\n", ptr-p, *ptr-a, **ptr);
  
       ++**ptr;
       printf("%d %d %d\n", ptr-p, *ptr-a, **ptr);
  
       return 0;
  }
  </code></pre>
  
  <p>I receive the output as.</p>
  
  <pre><code>1 1 1
  1 2 2
  1 2 3
  </code></pre>
  
  <p>I am facing a problem in justifying this output. I made lot of boxes on a copy for easy grasp of the problem. I am able to justify the output <code>1 1 1</code>, my trouble starts with the statement, <code>*++*ptr</code>. </p>
  
  <p>Since, a unary operators are executed from right to left. So, <code>*ptr</code> would be tackled first, then the value at <code>ptr</code> would be incremented. 
  After this increment, I am not sure what happens, the book says that somehow <code>p</code> is also incremented to point to the next element in this array. The output <code>1 2 2</code> can only be achieved through the increment of <code>p</code>.</p>
  
  <p>I am not sure that this kind of question fits exactly on stackoverflow.<br>
  I tried my best, wasted at least 10 pages with boxes drawn over them.</p>
  
  <p>Any clarification would be appreciated.</p>