Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA-21-02 Topic 5 Question 33 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 33
Topic #: 5
[All CPA-21-02 Questions]

Which line of code inserted instead of the comment will make the following code run properly without causing memory leaks?

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Francine
7 days ago
I'll have to go with Option D. It's the only one that seems to properly release the memory without any shenanigans.
upvoted 0 times
...
Cristal
14 days ago
Haha, Option A is just... delete this? I don't think that's how you fix memory leaks, my friend.
upvoted 0 times
...
Enola
15 days ago
I'm not sure, but I think option C is also a possibility. It deletes the pointer twice.
upvoted 0 times
...
Frederica
16 days ago
I agree with Salina, option D makes sense to prevent memory leaks.
upvoted 0 times
...
Cory
16 days ago
B? No additional code needed? Seriously? That's like saying 'just ignore the memory leak and hope for the best'.
upvoted 0 times
Mari
4 days ago
A) ~Base() { delete this; }
upvoted 0 times
...
...
Meghann
21 days ago
I think Option C is a trap. Deleting the same pointer twice is definitely going to cause a memory leak.
upvoted 0 times
Val
4 days ago
User1: I agree, deleting the same pointer twice is a bad idea.
upvoted 0 times
...
...
Jenelle
26 days ago
Option D looks good to me. We only need to call 'delete ptr;' once to release the memory.
upvoted 0 times
...
Salina
1 months ago
I think the correct answer is D) ~Base() { delete ptr; }
upvoted 0 times
...

Save Cancel