New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 1 Question 36 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 36
Topic #: 1
[All CPP Questions]

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

#include

#include

class A {

public:

virtual int f() { return 10; }

virtual ~A(){}

};

class B: public A {

int f() {return 11; }

virtual ~B(){}

};

int main (){

std::vectorv1;

for(int i = 10; i>0; i??)

{

i%2>0?v1.push_back(new A()):v1.push_back(new B());

}

std::vector::iterator it = v1.begin();

while(it != v1.end())

{

std::cout<f()<<" ";

v1.pop_back();++it;

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Stephanie
4 months ago
Nah, I think it won't compile due to the loop condition.
upvoted 0 times
...
Alyce
4 months ago
The destructors will be called correctly.
upvoted 0 times
...
Lavonna
4 months ago
Wait, are you sure about that?
upvoted 0 times
...
Chau
4 months ago
I think it outputs 10 11 10 11 10.
upvoted 0 times
...
Maia
5 months ago
The code will compile fine.
upvoted 0 times
...
Ahmad
5 months ago
I'm pretty sure this is asking about a vSphere feature that helps with optimization challenges. I think the answer is vSphere DRS, which automatically balances workloads across hosts.
upvoted 0 times
...

Save Cancel