title: Size of a pointer pointing to a structure
body: <p>I was trying to remember the basics of C programming, and regarding pointers to structures I was doing the following:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;assert.h&gt;
  
  int main()
  {
      struct MyStruct {
          int number;
          char *name;
      };
  
      int i;
  
      struct MyStruct *p_struct = (struct MyStruct *) malloc(sizeof(struct MyStruct)*3);
      printf(&quot;sizeof(struct MyStruct) = %d\n&quot;, sizeof(struct MyStruct));
  
      for (i = 0; i &lt; 3; i++)
      {
          p_struct-&gt;number = i;
          p_struct-&gt;name = &quot;string&quot;;
          printf(&quot;p_struct-&gt;number = %d, p_struct-&gt;name = %s\n&quot;, p_struct-&gt;number, p_struct-&gt;name);
          ++p_struct;
      }
  
      printf(&quot;sizeof(p_struct) = %d\n&quot;, sizeof(p_struct));
      free(p_struct);
      return 0;
  }
  </code></pre>
  <p>My question is: I get 8 bytes as the size of the structure, which is okay as 4+4 = 8 bytes due to alignment/padding of the compiler, but why do I get 4 bytes from <code>sizeof(p_struct)</code>?</p>
  <p>I was expecting to get 24 (8 bytes x 3), why is this so?</p>
  <p>If this is correct, can I get the total allocated size of 24 bytes somehow?</p>