Question: Consider the following variables in a program: 1 static int A ; 2 3 int main ( ) { 4 int B ; 5 int

Consider the following variables in a program:
1 static int A ;
2
3 int main (){
4 int B ;
5 int * C = new int (42);
6 foo ( C );
7 return 0;
8}
9
10 void foo ( int * ptr ){
11 int D ;
12 int * E = ptr ;
13 delete E ;
14 print ();
15}
1.[5 pts] Identify the storage allocation (static/stack/heap) for the following variables:
A, B, C, D, E, Pointer to C and Pointer to E?
2.[5 pts] Consider the following execution trace: 345610111213147.
For each of the following line numbers, list all active variables (allocated but not yet
deallocated) after the execution of that line. (Mention the pointer variables and
the objects they point to)
Example output for Line 5 : A, B, Pointer C, Object pointed by C
Line 3
Line 6
Line 11
Line 12
Line 13

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 Programming Questions!