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]

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:

Sharen
1 days 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
...
Lai
5 days ago
I think the answer is B) It prints: 10.
upvoted 0 times
...
Brynn
7 days 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
...

Save Cancel