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 CPP Topic 2 Question 99 Discussion

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

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

#include

#include

int main ()

{

std::vectorv1;

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

{

v1.push_back(i);

}

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

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Eun
5 days ago
The program will output 3 55. The erase function returns an iterator to the element after the last element removed, and we're dereference that iterator to get the value 3.
upvoted 0 times
...
Margret
7 days ago
The code will have a compilation error. You can't iterate over a vector and erase elements at the same time, it will cause undefined behavior.
upvoted 0 times
...
Lavina
18 days ago
I believe the program will output B) compilation error because of the syntax error in the code.
upvoted 0 times
...
Dorinda
21 days ago
I agree with Telma, there seems to be an issue with the code.
upvoted 0 times
...
Telma
25 days ago
I think the answer is B) compilation error.
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