+ 5
Deciphering Object Sizes of some classes - Why don't they appear the same as the calculated ones?
I must first show you some sizeof results in CppDroid: sizeof(int) -> 4 sizeof(double) -> 8 sizeof(char) -> 1 Now I tried deciphering some class object sizes using sizeof. I read somewhere that classes have the size of the members added together. So In my class: class Memory { char a; }m; cout<<sizeof(m); //Shows 1. But, class Memory2 { char a; int b; }m; cout<<sizeof(m); //Shows 8? And In derived classes, I get: class I:public Memory2 { char aaa;} i; cout<<sizeof(i); //Shows 16? Why ?
4 Réponses
+ 10
Have you maybe read this?
http://www.cprogramming.com/tutorial/size_of_class_object.html
+ 7
Is it due to use of a different compiler or is the compiler playing safe by reserving some extra memory for the class objects?
+ 7
I would appreciate it more if I recieved an answer for my question as well...😐😶
+ 4
@Dplusplus
I was aware of only step one, and hadn't read this before.
Thank You very much!