0 Answer
This answer partially references GPT, GPT_Pro to solve the problem better.
Because the structure has byte alignment principle, when calculating the size of the structure, The calculations need to be byte aligned. Specifically, you take the largest member variable in the structure as the alignment criterion, and then calculate how many bytes the other member variables need to fill so that the overall structure size always increases by a multiple of the largest member variable.
For example: In the example above, the largest member variable is float, float takes 4 bytes, so the byte size of this structure must be a multiple of 4, that is, the common body takes 5 bytes, int takes 4 bytes, char takes 1 byte, float takes 4 bytes, so these member variables will take 14 bytes, Because of byte alignment, the 14 bytes fill a multiple of float, so the final size of the structure should be 20 bytes.
If the answer is helpful, please accept it.
这家伙很懒,什么都没留下...