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:

Dalene
28 days ago
I bet the correct answer is a compilation error. I mean, come on, who writes code like this? It's like a riddle wrapped in a mystery inside an enigma.
upvoted 0 times
...
Gabriele
30 days ago
Hold on, is this the real life? Or is this just fantasy? I'm so confused, I think I need to go take a nap and come back to this question later.
upvoted 0 times
Huey
11 days ago
User1: Don't worry, just take a break and come back later.
upvoted 0 times
...
...
Lea
1 months ago
Wait, is this a trick question? I'm pretty sure the program will run forever because the while loop never terminates. It's like an infinite loop of finding adjacent duplicates!
upvoted 0 times
Mignon
5 days ago
E) program will run forever
upvoted 0 times
...
Cassie
7 days ago
C) program outputs: 3 8
upvoted 0 times
...
Kris
28 days ago
B) program outputs: 2 7
upvoted 0 times
...
Lorean
1 months ago
A) program outputs: 2 3
upvoted 0 times
...
...
Tawanna
2 months ago
I think the output will be 3 8, because the adjacent_find function will return the iterator pointing to the second pair of duplicates, which is the second 4 in the vector.
upvoted 0 times
Matthew
1 months ago
D) compilation error
upvoted 0 times
...
Cassi
1 months ago
C) program outputs: 3 8
upvoted 0 times
...
Irma
1 months ago
B) program outputs: 2 7
upvoted 0 times
...
Rosita
1 months ago
A) program outputs: 2 3
upvoted 0 times
...
...
Julieta
2 months 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 months 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
2 months 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
Billy
22 days ago
D) compilation error
upvoted 0 times
...
Terrilyn
28 days ago
C) program outputs: 3 8
upvoted 0 times
...
Curt
1 months ago
B) program outputs: 2 7
upvoted 0 times
...
Bobbie
2 months ago
A) program outputs: 2 3
upvoted 0 times
...
...
Tiffiny
3 months ago
I think the correct answer is A) program outputs: 2 3.
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