Consider the following class instances in a C++ program: static myClass A; int m
ID: 3923788 • Letter: C
Question
Consider the following class instances in a C++ program: static myClass A; int main() {myClass* B = new myClass (); foo(); delete B; return 0;} void foo() {myClass* C = new myClass(); myClass D;} What is the storage allocation (static/stack/heap) for the objects associated with A. B. C and D? 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 associated with A. B. C, and D, write down its lifetime (use a subset of execution trace, e.g., 12 13 to represent the lifetime).Explanation / Answer
a)
memory associated with
A - static
B - head (dynamically created)
C - heap (dynamically created)
D - stack
b)
life time:
A - 4,5,12,13,6,7
B - 4,5,6,7
C - 12, 13
D - 13
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.