a) Draw diagrams representing the following code and track the values of p1, p2, &var1, &var2, *p1, *p2, var1, and var2 at every checkpoint throughout the program. Clarify in your diagrams whether the storage is on the stack or heap. Assume initial addresses. int main() { int *p1; int *p2 = new int; int var1 =3; int var2= 6; *p1 = var1; p2 = new int; *p2 = 10; //CHECKPOINT1 var2 = 11; *p2 = var2; //CHECKPOINT2 p1 = p2; var2 = 30; //CHECKPOINT3 *p1 = 25; p2= &var1; *p2 = 16; //CHECKPOINT4 delete p1; p1 = nullptr; p2 = nullptr; return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

Computer Science

 

a) Draw diagrams representing the following code and track the values of p1, p2, &var1, &var2, *p1, *p2, var1, and var2 at every checkpoint throughout the program. Clarify in your diagrams whether the storage is on the stack or heap. Assume initial addresses.

int main() {

int *p1;
int *p2 = new int; int var1 =3;
int var2= 6;
*p1 = var1;
p2 = new int;
*p2 = 10; //CHECKPOINT1 var2 = 11;
*p2 = var2; //CHECKPOINT2 p1 = p2;
var2 = 30; //CHECKPOINT3 *p1 = 25;
p2= &var1;

*p2 = 16; //CHECKPOINT4 delete p1;
p1 = nullptr;
p2 = nullptr; return 0;

}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage