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;
>
union A{
long int y[5];
union B{
double g;
union C{
int k;
union D{
char ch;
int x[5];
};
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.
>
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