C++ Institute C++ Certified Professional Programmer CPP Question # 45 Topic 5 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 45 Topic 5 Discussion

CPP Exam Topic 5 Question 45 Discussion:
Question #: 45
Topic #: 5

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

#include

#include <algorithm>

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

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

vector v1(t, t + 10);

copy(t, t+10, v1.end());

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:


A.

10 5 9 6 2 4 7 8 3 1


B.

10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1


C.

compilation error


D.

runtime exception/segmentation fault


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.