[LCP]struct & union
shahnavaz
shan at ways.com
Mon Feb 4 16:01:20 UTC 2002
hi,
I think that has solved my doubt.But can you tell me why is int and float
have same size then(ofcourse on linux i386).
thanks & regards
shan
On Monday 04 February 2002 10:20 am, Chirag Kantharia wrote:
> On Mon, Feb 04, 2002 at 10:12:31AM +0530, shahnavaz wrote:
> | Can someone tell me why the sizeof returns 4 in the main function.Even
> | if i use int in place of float it returns 4.
>
> Because sizeof(int) is 4 (at least on linux on i386). And sizeof a union
> is the max size of the members within.
>
> | #include<stdio.h>
> | struct s{
> | float data;
> | };
> | struct c{
> | float c;
> | };
> | typedef union {
> | struct s ss;
> | struct c cc;
> | }Union;
> |
> | int main(void)
> | {
> | Union u;
> | printf("Size of Union is %d\n",sizeof(u));
> | return 0;
> | }
>
> chyrag.
More information about the linuxCprogramming
mailing list