Why is sizeof giving me this result?
<p>I have this code</p>

<pre><code>struct Student {
char name[48];
float grade;
int marks[10,5];
char gender;
};

Student s;
</code></pre>

<p>Now I have to get the sizeof s</p>

<p>so I added </p>

<pre><code>printf("%d",sizeof(s));
</code></pre>

<p>now when I hit compile the result showing is 256</p>

<p>and its wrong because it shoud be 253</p>

<p>as because the size of </p>

<p>char name[48];  ----> 48</p>

<p>and</p>

<p>float grade; -----> 4</p>

<p>and</p>

<p>int marks[10,5]; ------> 200</p>

<p>and</p>

<p>char gender; ------->1</p>

<p>so 48+4+200+1 = 253</p>

<p>so why is it telling me 256?</p>

<p>================================</p>

<p>this part is written after I saw your answers</p>

<p>I learned that</p>

<p>Suppose I have this structure: 
    struct  {
        char a[3];
        short int b;
        long int c;
        char d[3];
        };</p>

<p>So ..</p>

<pre><code>+-------+-------+-------+

|           a           |

+-------+-------+-------+

|       b       |

+-------+-------+-------+-------+

|               c               |

+-------+-------+-------+-------+

|           d           |

+-------+-------+-------+
</code></pre>

<p>In the <code>packed'' version, notice how it's at least a little bit hard for you and me to see how the b and c fields wrap around? In a nutshell, it's hard for the processor, too. Therefore, most compilers will</code>pad'' the structure (as if with extra, invisible fields) like this: </p>

<pre><code>+-------+-------+-------+-------+

|           a           | pad1  |

+-------+-------+-------+-------+

|       b       |     pad2      |

+-------+-------+-------+-------+

|               c               |

+-------+-------+-------+-------+

|           d           | pad3  |

+-------+-------+-------+-------+
</code></pre>

<p>so if Im having the maximum size is 200 should the padding be like</p>

<p>48 + 152</p>

<p>4 + 196</p>

<p>200 + 0</p>

<p>1 + 199</p>

<p>to make them in a perfect shape</p>
