Question: Whats is structure padding?Say a given structure Struct{ int a; char c; float d; } the size of structure is 7 here. But structure padding is done what will be the size of the struct?Will it change and how?How to avoid this?is it necessary?
Answer: Integers and floats :compilers will try to place these variables at addresses which are in multiples of 2 or 4(in 16-bit system) now in this case 1 byte can be padded...we can store integers and floats at start to avoid padding
Question:
Whats is structure padding?Say a given structure Struct{ int a; char c; float d; } the size of structure is 7 here. But structure padding is done what will be the size of the struct?Will it change and how?How to avoid this?is it necessary?
Answer:
Integers and floats :compilers will try to place these variables at addresses which are in multiples of 2 or 4(in 16-bit system) now in this case 1 byte can be padded...we can store integers and floats at start to avoid padding Source: CoolInterview.com
answer is 12.because the addresses are assigned to each var in the powers of their size and each size is of power 2.In structures the var are assigned in sequential order.if padding is not done then float may not satisfy these values.To satisfy these conditions structure padding is done. Source: CoolInterview.com