title: find if heap grows up
body: <p>In reference to the link below which explains how to find if the machine stack grows up ofr down in memory ... i want to know if the following would be the correct way to find if the machine's heap grows up or down in memory.</p>
  
  <p><a href="https://stackoverflow.com/questions/1163977/how-would-you-find-out-if-a-machines-stack-grows-up-or-down-in-memory-java">How would you find out if a machine’s stack grows up or down in memory? (JAVA)</a></p>
  
  <p>my code</p>
  
  <pre><code>void findHeapDirection(int *a) {
  
     int *b;
     b = (int*)malloc(sizeof(b));  
     printf("\naddress of a %x",a);   
     printf("\naddress of b %x",&amp;b);
  
     if(b &gt; a) 
       printf("\n&gt;&gt;heap grows up");
     else
      printf("\n&gt;&gt;heap grows down");   
  
      free(b);
  
    }   
  </code></pre>
  
  <p>and call this function like this</p>
  
  <pre><code> int *a;
   a = (int*)malloc(sizeof(a));
   findHeapDirection(a);
   free(a);
  </code></pre>
  
  <p>this was the output on my machine..</p>
  
  <pre><code>address of a 5417b0
  address of b 28ff14
  &gt;&gt;heap grows up
  </code></pre>
  
  <p><b><i>Or is this question ambiguous as heap can never grow downwards? </b></i></p>