So Basically I drew this conclusion ( Correct if I am wrong) On Gcc
char 1 byte but allocates 4 bytes padding 3 bytes for performance improvement. 4 double 8 bytes allocates 8 bytes ( multiple of 4 so no probs no padding) 8 int 4 bytes allocates 4 bytes. 4 ------------------------------------------------------------------------------------------------------------------------- Total 16 bytes On dev c++ and many other compilers char 1 byte allocates 8 bytes padding 7 bytes 8 double 8 bytes allocates 8 bytes 8 int 4 bytes allocates 8 bytes padding 4 bytes 8 ------------------------------------------------------------------------------------------------------------------------ Total 24 bytes This behavior occurs basically because of activation records the compilers use to store the variables in memory with gcc compiler takes 4 byte boundaries as activation records and dev c++ and other compilers taking activation record boundaries to be 8 bytes. Hope this is clear !! On Sat, Aug 6, 2011 at 11:28 PM, vikas singh <shyguy1...@gmail.com> wrote: > @sandeep > > I have executed it on gcc, it's showing 16 bytes(earlier post, the address > too) ... I'm sure now, this thing is PURILY compiler dependent.. > and it's your code buddy, not mine. ;) > > > > On Sat, Aug 6, 2011 at 7:37 PM, SANDEEP CHUGH <sandeep.aa...@gmail.com>wrote: > >> >> i hav executed ur code on dev c++.. i m getting correct out put as 24. >> when i hav executed ur code on turbo version it shows 11 ,i.e it is doing >> no padding at all.. >> On Sat, Aug 6, 2011 at 7:21 PM, vikas singh <shyguy1...@gmail.com> wrote: >> >>> @sandeep >>> >>> >>> size = 16 address=3220095484 >>> size = 16 address=3220598412 >>> size = 16 address=3214020060 >>> size = 16 address=3214400060 >>> size = 16 address=3216088732 >>> size = 16 address=3220983548 >>> size = 16 address=3219062412 >>> size = 16 address=3214817228 >>> >>> >>> >>> this is my continuous execution of your code >>> struct node >>> >>> { >>> char c; >>> double d; >>> int s; >>> }; >>> int main(){ >>> struct node a; >>> struct node *p; >>> p=&a; >>> printf("size = %d \t address=%u", sizeof(a), p); >>> } >>> >>> I don't know why you said 24 in the thread.. is it compiler dependent ?? >>> >>> -- >>> Thanks and Regards >>> VIKAS SINGH >>> MCA- final year >>> NIT DURGAPUR >>> email: >>> vikas.singh1...@gmail.com >>> shyguy1...@gmail.com >>> http://smrit.wordpress.com >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Thanks and Regards > VIKAS SINGH > MCA- final year > NIT DURGAPUR > email: > vikas.singh1...@gmail.com > shyguy1...@gmail.com > http://smrit.wordpress.com > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Regards Rajeev N B <http://www.opensourcemania.co.cc> "*Winners Don't do Different things , they do things Differently"* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.