Does this type of memory get allocated on the heap or the stack?
问题 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. 回答1: Given a slight modification of your example: class Foo{ private: int x[100]; int *y; public: Foo() { y = new int[100]; } ~Foo(