Question: 1 static myClass* X; 2 int main() 3 ( 4 5 6 7 9 10 11 12 13. 14 } Consider the following class
1 static myClass* X; 2 int main() 3 ( 4 5 6 7 9 10 11 12 13. 14 } Consider the following class instances in a C++ program: myClass Y = new myClass (); foo (); delete Y; return 0; void foo () { myClass Z; X= new myClass(); a) (5pt) What is the storage allocation (static/stack/heap) for the following objects? 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) (5pt) Consider one execution of the program above. The execution trace (a sequence of program state- ments 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
3.50 Rating (170 Votes )
There are 3 Steps involved in it
a object A Global static pointer variable and will be saved in heap storage obj... View full answer
Get step-by-step solutions from verified subject matter experts
