@Dheeraj, Thanks for the link
@Anshul
Considering double to be alligned as a 4 byte boundary..
structc_tag

c 1 byte
padding 1 byte
padding 1 byte
padding 1 byte
double 8 byte
int    4 byte

whole structure is multiple of 4 so no padding required.

structd_tag

8 byte for double
4 byte for int
1 byte for char
 padding 3 byte

last 3 byte padding for structure size to be multiple of 4

Correct me if am wrong....

On Sun, Sep 4, 2011 at 2:40 AM, Anshul AGARWAL
<[email protected]> wrote:
> #include <stdio.h>
>
> // structure C
> typedef struct structc_tag
> {
>    char        c;
>    double      d;
>    int         s;
> } structc_t;
>
> // structure D
> typedef struct structd_tag
> {
>    double      d;
>    int         s;
>    char        c;
> } structd_t;
>
> int main()
> {
>
>
>    printf("sizeof(structc_t) = %d\n", sizeof(structc_t));
>    printf("sizeof(structd_t) = %d\n", sizeof(structd_t));
>
>    return 0;
> }
> plz explain the output ??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to