In the context of C++ (not that it matters):
class Foo{ private: int x[100]; public: Foo(); }
What I’ve learnt tells me that if you create an instance of Foo like so:
Foo bar = new Foo();
Then the array x is allocated on the heap, but if you created an instance of Foo like so:
Foo bar;
Then it’s created on the stack.
I can’t find resources online to confirm this.
Given a slight modification of your example:
Example 1:
Example 2:
Actual sizes may differ slightly due to class/struct alignment depending on your compiler and platform.