Question: 1 2 3 Problem 1 [5pt] Consider the following class instances in a C++ program: static myclass* X; int main() { myClass* Y = new

 1 2 3 Problem 1 [5pt] Consider the following class instances

1 2 3 Problem 1 [5pt] Consider the following class instances in a C++ program: static myclass* X; int main() { myClass* Y = new myClass(); foo(); delete Y; return 0; } 4 5 6 7 8 9 10 11 12 void foo () { myClass Z; X = new myClass(); } 13 14 a) (2.5pt) What is the storage allocation (static/stack/heap) for the following objects? C . . object A: the pointer X object B: the pointer Y object C: the myClass object created at line 4 object D: the myClass object created at line 12 object E: the myClass object created at line 13 . b) (2.5pt) 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 above (i.e., object A to E), write down its lifetime (use a subset of execution trace, e.g., 12 13 to represent the lifetime). Assume the lifetime of a heap-allocated object starts from new and ends after delete and include both new and delete

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!