title: Understanding the stack address manipulation
body: <blockquote>
    <p>Consider the following piece of code (on a 32-bit Intel/Linux system):</p>
  
  <pre><code>struct mystruct {
    char a;
    int b;
    short c;
    char d;
  };
  int main()
  {
    struct mystruct foo[3];
    char ch;
    int i;
  
    printf("%p %p %p %p %p\n", &amp;foo[0], &amp;foo[1], &amp;foo[2], &amp;ch, &amp;i);
  
    return 0;
  }
  </code></pre>
    
    <p>Which of the following would be the most likely candidate for its output?</p>
    
    <ol>
    <li><code>0xfeeece90 0xfeeece9c 0xfeeecea8 0xfeeece8f 0xfeeece88</code></li>
    <li><code>0xfeeece90 0xfeeece9c 0xfeeecea8 0xfeeeceb4 0xfeeeceb8</code></li>
    <li><code>0xfeeece90 0xfeeece9c 0xfeeecea8 0xfeeeceb4 0xfeeeceb5</code></li>
    <li><code>0xfeeece90 0xfeeece9c 0xfeeecea8 0xfeeece8c 0xfeeece88</code></li>
    </ol>
  </blockquote>
  
  <p>The output is option (1). I could not understand, how the option a is the right answer.. </p>
  
  <p>Stack grows from higher addresses to lower addresses. Here <code>foo[3]</code>, <code>foo[2]</code>, <code>foo[1]</code>, <code>foo[0]</code>, <code>ch</code>, <code>i</code> ... <code>i</code> will be at the lower address of stack and <code>foo[3]</code> at the higher address. Here the <code>sizeof(mystruct)</code> is 16, hence the <code>foo[3]</code>, <code>foo[2]</code>, <code>foo[1]</code>, <code>ch</code> will be laid with the address gap of 16.</p>
  
  <p>I couldn't get the address difference 16 here with the below address:</p>
  
  <pre><code>0xfeeece90 0xfeeece9c 0xfeeecea8 0xfeeece8f 0xfeeece88
  </code></pre>