+1

Why the output is 8 bytes instead of 6 bytes??

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

9/3/2019 10:33:11 AM

Noor ❤

8 Answers

New Answer

+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.

+5

2 bytes have been padded, resulting in 8 bytes. 4 bytes int + 2 bytes char + 2 padding bytes...

+4

see this Noor ❤ https://www.sololearn.com/post/78037/?ref=app

+4

✳AsterisK✳ I got it now. Thanks for making the things easy to understand

+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

+3

✳AsterisK✳ Yes it's structure padding at work. You have found a good link (Babak's one) go through it and let me know if you need explanation for anything.

+2

Use so: https://code.sololearn.com/cDUtFj1Ra4jv/?ref=app

+1

Kuri do structure reserves 2 bytes for padding?