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