Size of structure with a char, a double, an int and a t
<p>When I run only the code fragment</p>

<pre><code>int *t;
std::cout &lt;&lt; sizeof(char)   &lt;&lt; std::endl;
std::cout &lt;&lt; sizeof(double) &lt;&lt; std::endl;
std::cout &lt;&lt; sizeof(int)    &lt;&lt; std::endl;
std::cout &lt;&lt; sizeof(t)      &lt;&lt; std::endl;
</code></pre>

<p>it gives me a result like this:</p>

<pre><code>1
8
4
4
</code></pre>

<p>Total: 17.</p>

<p>But when I test sizeof struct which contains these data types it gives me 24, and I am confused. What are the additional 7 bytes?</p>

<p>This is the code</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
struct struct_type{
    int i;
    char ch;
    int *p;
    double d;
} s;

int main(){
    int *t;
    //std::cout &lt;&lt; sizeof(char)   &lt;&lt;std::endl;
    //std::cout &lt;&lt; sizeof(double) &lt;&lt;std::endl;
    //std::cout &lt;&lt; sizeof(int)    &lt;&lt;std::endl;
    //std::cout &lt;&lt; sizeof(t)      &lt;&lt;std::endl;

    printf("s_type is %d byes long",sizeof(struct struct_type));

    return 0;
}
</code></pre>

<p>:EDIT</p>

<p>I have updated my code like this</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
struct struct_type{
    double d_attribute;
    int i__attribute__(int(packed));
    int * p__attribute_(int(packed));;
    char  ch;
} s;

int main(){
    int *t;
    //std::cout&lt;&lt;sizeof(char)&lt;&lt;std::endl;
    //std::cout&lt;&lt;sizeof(double)&lt;&lt;std::endl;
    //std::cout&lt;&lt;sizeof(int)&lt;&lt;std::endl;
    //std::cout&lt;&lt;sizeof(t)&lt;&lt;std::endl;

    printf("s_type is %d bytes long",sizeof(s));

    return 0;
}
</code></pre>

<p>and now it shows me 16 bytes. Is it good, or have I lost some important bytes?</p>
