Please help Consider the following class instances in a C pr
Please help
Consider the following class instances in a C++ program: static myClass A; int main() {myClass* B = new myClass(); foo (); delete B; return 0;} void foo() {myClass* C = new myClass(); myClass D;} What is the storage allocation (static/stack/heap) for the objects associated with A, B, C and D? Consider one execution of the program above. The execution trace, a sequence of program statements executed at run time, of this program is 4 5 12 13 6 7 For each object associated with A, B, C, and D, write down its lifetime (use a subset of execution trace, e.g., 12 13 to represent the lifetime).Solution
a) Object A will have static allocation as it has been declared as static.
Objects B and C will have dynamic or Heap allocation as new operator always allocates memory dynamically
Object D will have stack allocation.
b) A {4, 5, 12, 13, 6, 7}
B {4, 5, 12, 13, 6}
C {12, 13}
D {13}
