BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

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

Posted by Jolanda on May 03, 2022 at 11:13 PM

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;

}

Suggested Answer: D

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
6 comments · newest first
ST
Stephanie 1 year ago
Nah, I think it won't compile due to the loop condition.
AL
Alyce 1 year ago
The destructors will be called correctly.
LA
Lavonna 1 year ago
Wait, are you sure about that?
CH
Chau 1 year ago
I think it outputs 10 11 10 11 10.
MA
Maia 1 year ago
The code will compile fine.
AH
Ahmad 1 year 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.
0/2000 characters

Save Cancel