+ 2

Why the code below is giving the output 16?

https://code.sololearn.com/c5xjD04chN8o/?ref=app

19th Apr 2020, 12:08 PM
Manthan Gohel
Manthan Gohel - avatar
8 Réponses
+ 5
There is a concept of padding, alignment and data packing in structure which is the cause for occupying extra space. Reference link https://www.geeksforgeeks.org/structure-member-alignment-padding-and-data-packing/ This thread has some discussion on it. https://www.sololearn.com/Discuss/2053833/?ref=app
19th Apr 2020, 12:33 PM
Avinesh
Avinesh - avatar
+ 2
It is because there are two variables and both are sharing same memory area for this particular case that is 8 and 8...
19th Apr 2020, 12:26 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 2
Avinesh Thank you very much!
19th Apr 2020, 1:31 PM
Manthan Gohel
Manthan Gohel - avatar
+ 2
Manthan Gohel Welcome. Nice to know it helped.
19th Apr 2020, 2:37 PM
Avinesh
Avinesh - avatar
+ 1
Something seems to be missing. int is size 4, char* size 8. How does that become 16?
19th Apr 2020, 12:32 PM
HonFu
HonFu - avatar
+ 1
But in this particular case it is taking 8 bytes for int also , if one more int variable is defined then also it is printing same answer
19th Apr 2020, 12:34 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 1
~ swim ~ Also thank you too.
19th Apr 2020, 3:10 PM
Manthan Gohel
Manthan Gohel - avatar