storage allocation, lifetime

Question Description

I need support with this Computer Science question so I can learn better.
Problem 1
Problem 1 [15pt] Consider the following class instances in a C++ program: 1 static myClass* X; 2 int main() 3 { 4 myClass* Y = new myClass(); 5 foo(); 6 delete X; 7 return 0; 8 } 9 10 void foo() 11 { 12 myClass Z; 13 X = new myClass(); 14 } 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) (10pt) 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.

admin

Author Since: November 30, 2020