C++ Institute C++ Certified Professional Programmer CPP Question # 19 Topic 2 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 19 Topic 2 Discussion

CPP Exam Topic 2 Question 19 Discussion:
Question #: 19
Topic #: 2

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

#include

#include <algorithm>

#include

#include

using namespace std;

bool identical(int a, int b) {

return b == 2*a?true:false;

}

int main() {

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

int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};

vector v1(t, t + 15);

deque d1(u, u + 15);

pair::iterator, vector::iterator > result;

result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I

if (result.first == d1.end() && result.second == v1.end()) {//Line II

cout<<"Identical\n";

} else {

cout<<"Not identical\n";

}

return 0;

}

Program outputs:


A.

Identical


B.

Not identical


C.

compilation error at line marked I


D.

compilation error at line marked II


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.