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 3 Question 16 Discussion

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

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 0; i<10; i++) {v1.push_back(i); }

std::vector v2(v1.begin()+2, v1.end()?2);

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

for( ; it != v2.end(); it++) {std::cout<<*it++<<" "; }std::cout<

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Lashanda
4 months ago
Nah, I think it outputs 2 4 6 instead.
upvoted 0 times
...
Vivan
4 months ago
It's supposed to output 2 3 4 5 6 7, right?
upvoted 0 times
...
Jaclyn
4 months ago
Wait, is that really a compilation error? I thought it might run.
upvoted 0 times
...
Curt
4 months ago
I agree, that line is definitely off!
upvoted 0 times
...
Mitzie
5 months ago
Looks like a compilation error due to the wrong use of end()?
upvoted 0 times
...
Weldon
5 months ago
Hmm, I'm a bit confused about the difference between publishing changes and running the solution checker. I'll need to review those steps carefully.
upvoted 0 times
...
Abraham
5 months ago
This is a tricky one, the privacy statement has a lot of details to parse through. I'm going to re-read it carefully and think through each option before making my final decision.
upvoted 0 times
...
Margarita
5 months ago
Disabling SSLv3 is a no-brainer for security these days. I'll definitely select that one.
upvoted 0 times
...

Save Cancel