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 4 Question 63 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 63
Topic #: 4
[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,4,5,1,2,3,5,4};

vector v (t,t+10);

vector::iterator it;

int m1[] = {1, 3, 2};

it = find_end (v.begin(), v.end(), m1, m1+3);

if (it != v.end())

cout << "Found at position: " << it?v.begin() << endl;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Elly
14 days ago
Ha! I bet the answer is 'D' - 'program outputs: Found at position: 10'. The 'find_end' function returns an iterator pointing to the last element of the found sequence, so we need to subtract the beginning of the vector to get the actual position. Classic C++ gotcha!
upvoted 0 times
...
Ciara
15 days ago
Wait, what? The code is trying to print the position of the found sequence, but it's using 'it?v.begin()' instead of 'it - v.begin()'. That's not going to work. I bet the output is going to be a bit... unexpected.
upvoted 0 times
...
Yong
19 days ago
Okay, let's see. The code is using the 'find_end' function from the 'algorithm' library to search for the sequence {1, 3, 2} in the vector 'v'. Sounds good so far.
upvoted 0 times
...
Alberta
2 months ago
Hmm, I think this code is trying to find the last occurrence of the sequence {1, 3, 2} in the vector 'v'. If it finds it, it should print the position. Let me think this through...
upvoted 0 times
Marjory
16 days ago
User2: Program outputs: Found at position: 5
upvoted 0 times
...
Stephaine
20 days ago
User1: I think the code is looking for the sequence {1, 3, 2} in the vector.
upvoted 0 times
...
...
Michael
2 months ago
I'm not sure, but I think the answer might be D.
upvoted 0 times
...
Shelton
2 months ago
I disagree, I believe the answer is B.
upvoted 0 times
...
Toshia
2 months ago
I think the answer is A.
upvoted 0 times
...

Save Cancel