Memory allocation when declaring a series of class objects in C++

Viewed 81
class Data {
    double a, b, c;
};

int main() {
    Data x, y, z;
    cout << sizeof(x) << endl;
    cout << &x << " " << &y << " " << &z << endl;
}

The output of the above code was:

24
0x7ffd911f5640 0x7ffd911f5660 0x7ffd911f5680

Here's my question: The Data class object needs only 24 bytes of space, then why the compiler allocates 32 bytes (memory spaces between 0x7ffd911f5640 and 0x7ffd911f5660) for each object instead?

0 Answers
Related