Structure padding is done by the compilers and this depends on the architectures. Some architectures cannot access the data which will be stored on the odd addresses or they may find difficult to access it. This is the reason for padding extra bytes.
Padding will be done by compiler to structure’s members and to the structure as a whole also. Compiler pads structure as whole because this allows each member of structure aligned in array of structures
Structure padding example
Short int c;
Due to structure padding this structure size is going to be :
(a[1 byte + padding 3 byte + b[4 byte] + c[2 byte] + 2 byte padding = 12byte ) instead of 7 byte.
Byte padding exists for both classes and structures
Resolving technical problems:
Solve your technical problems instantly
We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM
Mail your problem details at [email protected] along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.