Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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]

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class BaseC

{

int *ptr;

public:

BaseC() { ptr = new int(10);}

BaseC(int i) { ptr = new int(i); }

~BaseC() { delete ptr; }

void Print() { cout << *ptr; }

};

int main()

{

BaseC *o = new BaseC(5);

o?>Print();

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Lanie
1 months ago
I'm going to go with B. It's the most likely option, and I'm not going to overthink this. Time to move on to the next question!
upvoted 0 times
Leah
9 days ago
I agree, it should print: 5
upvoted 0 times
...
Pamella
15 days ago
I think it prints: 5
upvoted 0 times
...
...
Donte
2 months ago
Haha, this is a classic pointer-related question. I bet the answer is B, just to mess with us all!
upvoted 0 times
Valentin
14 days ago
User 3: I'm going with C on this one.
upvoted 0 times
...
Weldon
15 days ago
User 2: No way, it's definitely B.
upvoted 0 times
...
Kayleigh
1 months ago
User 1: I think the answer is A.
upvoted 0 times
...
...
Melinda
2 months ago
Wait, are we sure the object is being deleted properly? If there's a memory leak, it might print some random value like 1 or 0.
upvoted 0 times
Chantell
2 days ago
User3: Wait, but what if there's a memory leak? It could print a random value.
upvoted 0 times
...
Marguerita
3 days ago
User2: Yeah, it should print 5 since we're passing 5 to the constructor.
upvoted 0 times
...
Dorsey
7 days ago
Always remember to properly manage memory in your code.
upvoted 0 times
...
Yuette
15 days ago
Memory leaks can cause unexpected values to be printed.
upvoted 0 times
...
Jillian
23 days ago
User1: It prints: 5
upvoted 0 times
...
Micaela
28 days ago
It prints: 5
upvoted 0 times
...
Lawrence
1 months ago
Make sure to check for memory leaks in the code.
upvoted 0 times
...
...
Lai
2 months ago
That makes sense, but I'm not sure. Let's see what others think.
upvoted 0 times
...
Nguyet
2 months ago
I believe the answer is A) It prints: 5 because the object is initialized with 5.
upvoted 0 times
...
Sharen
2 months ago
Hmm, I'm not so sure. What if the compiler optimizes the code and the object ends up being created with the default constructor instead of the one that takes an argument? Then it would print 10.
upvoted 0 times
Candra
1 months ago
User 2: I think it prints: 10
upvoted 0 times
...
Mary
1 months ago
User 1: It prints: 5
upvoted 0 times
...
...
Lai
2 months ago
I think the answer is B) It prints: 10.
upvoted 0 times
...
Brynn
2 months ago
The code will print 5, as we create a BaseC object with the constructor that takes an integer argument and pass in the value 5.
upvoted 0 times
Eden
16 days ago
C) It prints: 5
upvoted 0 times
...
Van
18 days ago
B) It prints: 5
upvoted 0 times
...
Leana
2 months ago
A) It prints: 5
upvoted 0 times
...
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77