union A{ long int y[5]; union B{ double g; union C{ int k; union D{ char ch; int x[5]; }; }; }; };
just removed the instances of unions from the given declaration and tested on dev A 20 B 8 C 4 D 20 On Sat, Dec 8, 2012 at 6:39 PM, shiv narayan <narayan.shiv...@gmail.com>wrote: > but when i compile it on Dev C it gives 24..whats the reason ? > > > On Fri, Dec 7, 2012 at 7:19 AM, Don <dondod...@gmail.com> 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 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 the same, because there is nothing bigger in any of >> them. >> sizeof(A) will be 40 which is the size of an array of eight long ints. >> Don >> >> >> On Dec 7, 5:42 am, zerobyzero <narayan.shiv...@gmail.com> wrote: >> > what will be the size of union A ,B,C and D. also please explain the >> logic. >> > >> > * union A{* >> > * long int y[5];* >> > * union B{* >> > * double g;* >> > * union C{* >> > * int k;* >> > * union D{* >> > * char ch;* >> > * int x[5];* >> > * }s;* >> > * }a;* >> > * }b;* >> > * }*p;* >> >> -- >> >> >> > > > -- > Shiv Narayan Sharma > Jt. Secretary CSI-DTU > +919971228389 > www.jugadengg.com > > > > -- > > > -- Regards, Aashish Mann --