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 1 Question 12 Discussion

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

Lashawnda
21 hours ago
I also agree with user_1. Deleting the pointer in the destructor is essential to prevent memory leaks.
upvoted 0 times
...
Clorinda
2 days ago
I think the correct answer is D) ~Base() { delete ptr; } because we need to delete the pointer to prevent memory leaks.
upvoted 0 times
...
Lashandra
24 days ago
Alright, let's break this down. The code is missing the implementation of the Base class destructor, and we need to ensure that the memory allocated for the ptr member is properly released. I think option D is the way to go. Simple and effective!
upvoted 0 times
...
Carlee
26 days ago
You know, I'm still a bit confused about the whole pointer thing. Is the ptr variable a member of the Base class? I need to review my C++ fundamentals before this exam.
upvoted 0 times
...
Altha
27 days ago
Haha, I bet the exam writers are trying to trick us with those answer choices. C is clearly wrong, since deleting the pointer twice would result in a double-free error. That's a big no-no!
upvoted 0 times
...
Daniel
28 days ago
I agree with Marvel, but I'm also curious about option B. Could it be that no additional code is needed if the Base class has a proper default destructor implementation? That would be the simplest solution.
upvoted 0 times
...
Marvel
30 days ago
Okay, let's think this through. The code is missing the destructor implementation for the Base class, which could lead to a memory leak. I'm leaning towards option D, since deleting the pointer once should do the trick.
upvoted 0 times
...
Gaynell
1 months ago
Whoa, this question is tricky! I'm not sure I even understand the code, let alone the right answer. Memory leaks are such a pain to deal with.
upvoted 0 times
...

Save Cancel