Are data members allocated in the same memory space as their objects in C++?

Test a;
Test *t = new Test;

a, and all its members, are on the stack.

The object pointed to by t, and all its members, are on the heap.

The pointer t is on the stack.

Leave a Comment