Question: Storage Allocation Mechanism and Object Lifetime Consider the following variables in a C + + program: 1 static myClass A ; 2 3 int main

Storage Allocation Mechanism and Object Lifetime
Consider the following variables in a C++ program:
1 static myClass A ;
2
3 int main (){
4 myClass B ;
5 myClass * C = foo ();
6 myClass * D = new myClass ();
7 delete C ;
8 return 0;
9}
10
11 void foo (){
12 myClass E ;
13 return new myClass ();
14}
1. What is the storage allocation (static/stack/heap) for the objects of type myClass
associated with A, B, C, D, and E?
2. Consider one execution of the program above. The execution trace, a sequence of
program statements executed at run time, of this program is 3451213678
For each object associated with A, B, C, D, and E, write down its lifetime using a
subset of the above execution trace (e.g.,4512136). Note, that the answer subset
might be non-strict, i.e., the whole trace.

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!