title: Can anyone explain and trace this because my teacher can't
body: <p>the question in the exam was :</p>
  
  <p>write the output of the following program :</p>
  
  <pre><code>int i = 2 ;
  int main () {
  
      int j = 10, p ;
      while (i-- &amp;&amp; p == fork())
          if ( p &lt; 0 ) exit(1);
      j += 2;
      if (p == 0) {
          i *= 3;
          j *= 3;
      }
      else {
          i *= 2;
          j *= 2;
      }
  
      printf("i = %d, j = %d \n",i,j);
  
      return 0;
  }
  </code></pre>
  
  <p>Output from the console using xcode with include this lines before <code>int i = 2;</code> :</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;unistd.h&gt;
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>i = 3, j = 36 
  i = 0, j = 36 
  i = -3, j = 36 
  </code></pre>
  
  <p>Note: I notice that the output is different if we use the Ubuntu.</p>
  
  <p>i think this is the output of the Ubuntu :</p>
  
  <pre><code>i = 2 , j = 24
  i = 2 , j = 24
  </code></pre>
  
  <p>any brief explain or trace would be great Thanks </p>