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 7 Question 86 Discussion

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

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

#include

#include

#include

using namespace std;

int main () {

int t[] = {1,2,3,3,5,1,2,4,4,5};

vector v (t,t+10);

vector::iterator it = v.begin();

while ( (it = adjacent_find (it, v.end())) != v.end()) {

cout<

}

cout<< endl;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Julieta
1 days ago
I'm not sure, but I think the answer might be B) program outputs: 2 7 because the iterator is incremented by 1 each time.
upvoted 0 times
...
Lashonda
2 days ago
I agree with Tiffiny, because the code uses adjacent_find to find the first occurrence of two adjacent elements that are equal.
upvoted 0 times
...
Malcolm
7 days ago
The output will be 2 7, since the adjacent_find function will return the first iterator pointing to the first duplicate element, which is the second 3 in the vector.
upvoted 0 times
...
Tiffiny
14 days ago
I think the correct answer is A) program outputs: 2 3.
upvoted 0 times
...

Save Cancel