[algogeeks] Re: HOW TO CALCULATE THA size of union

2012-12-10 Thread Don
Your code is different from the original question. You don't declare an instance of D, C, or B. Just declaring the type does not allocate any storage. Don On Dec 10, 12:29 pm, ashish mann wrote: >  union A{ >           long int y[5]; >           union B{ >                    double g; >          

Re: [algogeeks] Re: HOW TO CALCULATE THA size of union

2012-12-10 Thread ashish mann
union A{ long int y[5]; union B{ double g; union C{ int k; union D{ char ch; int x[5]; };

Re: [algogeeks] Re: HOW TO CALCULATE THA size of union

2012-12-08 Thread shiv narayan
but when i compile it on Dev C it gives 24..whats the reason ? On Fri, Dec 7, 2012 at 7:19 AM, Don wrote: > The actual size is system dependent because the language doesn't > specify the size of int or long int. > I'll assuming the common convention that sizeof(int)=4 and sizeof(long > int)=8. >

[algogeeks] Re: HOW TO CALCULATE THA size of union

2012-12-07 Thread Don
The actual size is system dependent because the language doesn't specify the size of int or long int. I'll assuming the common convention that sizeof(int)=4 and sizeof(long int)=8. The size of a union is the size of the largest element in the union. So sizeof(D) = 5*sizeof(int)=20 C and B will be t