+ 3
I didn't understand this code
union abc{ char a,b,c,d,e,f,g,h; int i; }abc; int main(){ printf("%d",sizeof(abc)); return 0; } Output given is 4 .. but how??
4 Antworten
+ 1
Output is sizeof int 4bytes.
For the union, storage is allocated is the bigest size of type in that union...
There char type requires only 1bytes and int requires 4bytes. So biggest is 4bytes is alloted by that union.
And each time only one type value is stored of that unoin value, by most recent calculations on that union values.
If you add double type then you get output as 8.
+ 2
union, storage is allocated the bigest size of type .
There char type requires only 1bytes and int allocate 4bytes. So biggest is 4bytes is alloted by that uniton
I
+ 1
It depends on the alignment that the compiler puts into the allocated space. So, unless you use some special option, the compiler will put padding into your union space.
0
Output is sizeof int 4bytes.
For the union, storage is allocated is the bigest size of type in that union...
There char type requires only 1bytes and int requires 4bytes. So biggest is 4bytes is alloted by that union.
And each time only one type value is stored of that unoin value, by most recent calculations on that union values.
If you add double type then you get output as 8.