Stack memory layout in c
<p>I have written a small program for learning about the stack pointer in C. Usually, the stack pointer points to the last address of RAM.  For example, I run this code in Linux, which has the stack pointer in last address (<code>0x7fffffffffff</code>) but the variables are stored in these addresses (for this program):</p>

<pre><code>c --&gt; 0x7ffc67ca5c94
b --&gt; 0x7ffc67ca5c98
a --&gt; 0x7ffc67ca5c9c
</code></pre>

<p>Code:</p>

<pre><code>void fun(int *ptr)
{
   printf("c --&gt; %p\n",ptr);
   ptr++;
   printf("b --&gt; %p\n",ptr);
   ptr++;
   printf("a --&gt; %p\n",ptr);
}

int main() 
{
   int a = 10,b = 20,c = 30;
   printf("%p     %p    %p\n",&amp;a,&amp;b,&amp;c);
   fun(&amp;c);
   return 0;    
}
</code></pre>

<p>Output for this program:</p>

<pre><code>0x7ffc67ca5c9c     0x7ffc67ca5c98    0x7ffc67ca5c94
c --&gt; 0x7ffc67ca5c94
b --&gt; 0x7ffc67ca5c98
a --&gt; 0x7ffc67ca5c9c
</code></pre>

<p>My questions are:</p>

<ol>
<li><p>Why are the variables not stored in last section of the stack frame (0x7fffffffffff) which skips some memory locations and gets stored? Any valid reason for such behavior?</p></li>
<li><p>Why the stack pointer address has six bytes?</p></li>
</ol>

<p>I am working on a 64-bit machine with a 32-bit GCC compiler.</p>