Why does the size of a class depends on the order of the member declaration? and How?
Someone explain me how does the order of the member declaration inside a class determines the size of that class. For Example : class temp { public: int i; short s; char c; }; The size of above class is 8 bytes. But when the order of the member declaration is changed as below class temp { public: char c; int i; short s; }; then the size of class is 12 bytes. How? fayyazkl The reason behind above behavior is data structure alignment and padding . Basically if you are creating a 4 byte variable e.g. int, it will be aligned to a four byte boundary i.e. it will start from an address in memory,