BlackFriday 2024! 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 1 Question 24 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 24
Topic #: 1
[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:

Ty
1 months ago
I believe option B is incorrect, some code is needed to properly manage memory.
upvoted 0 times
...
Kina
1 months ago
I'm not sure, but I think option C might also work since it deletes ptr twice.
upvoted 0 times
...
Avery
1 months ago
I agree with Jospeh, option D makes sense to prevent memory leaks.
upvoted 0 times
...
Jenise
2 months ago
Option B is just wishful thinking. No code? Really? That's not how C++ works, folks.
upvoted 0 times
...
Onita
2 months ago
Haha, I bet the person who wrote Option C must have been napping during the memory management lecture. Rookie mistake!
upvoted 0 times
...
Susana
2 months ago
I agree with Allene. Deleting the pointer twice like in Option C is a common mistake that can cause issues.
upvoted 0 times
Van
11 days ago
Always important to be careful with memory management in code.
upvoted 0 times
...
Almeta
17 days ago
I agree, Option D is the safest choice to prevent memory leaks.
upvoted 0 times
...
Junita
22 days ago
Yeah, I think Option C is definitely wrong. Deleting the pointer twice is a bad idea.
upvoted 0 times
...
Domitila
27 days ago
Option D is the correct one. It deletes the pointer once to avoid memory leaks.
upvoted 0 times
...
...
Allene
2 months ago
Option D is clearly the correct answer. You only need to delete the pointer once to avoid memory leaks.
upvoted 0 times
Renea
1 months ago
Yeah, you just need to delete the pointer once.
upvoted 0 times
...
Dana
2 months ago
Option D is the correct answer.
upvoted 0 times
...
...
Jospeh
2 months ago
I think the answer is D) ~Base() { delete ptr; }
upvoted 0 times
...

Save Cancel