Why the output is 8 bytes instead of 6 bytes?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
3rd Sep 2019, 10:33 AM
Noor ❤
Noor ❤ - avatar
7 Answers
+ 6
Need not be. if struct elements are not aligned to it's memory, then only padding will be done. In 32 bit system, struct size shall be 32 bit aligned. Padding improves performance.
3rd Sep 2019, 11:01 AM
Kuri
Kuri - avatar
+ 5
2 bytes have been padded, resulting in 8 bytes. 4 bytes int + 2 bytes char + 2 padding bytes...
3rd Sep 2019, 10:42 AM
Kuri
Kuri - avatar
3rd Sep 2019, 12:36 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 4
✳AsterisK✳ I got it now. Thanks for making the things easy to understand
3rd Sep 2019, 2:02 PM
Noor ❤
Noor ❤ - avatar
+ 3
i think ~ swim ~ have explained this before, the structure padding works in blocks of 4 or something i can't remember clearly cause am also struggling in this context
3rd Sep 2019, 12:31 PM
✳AsterisK✳
✳AsterisK✳ - avatar
4th Sep 2019, 5:13 AM
UraL
+ 1
Kuri do structure reserves 2 bytes for padding?
3rd Sep 2019, 10:47 AM
Noor ❤
Noor ❤ - avatar