C++ Institute C++ Certified Professional Programmer CPP Question # 3 Topic 1 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 3 Topic 1 Discussion

CPP Exam Topic 1 Question 3 Discussion:
Question #: 3
Topic #: 1

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

#include

#include <algorithm>

#include

using namespace std;

void myfunction(pair i) {

cout << " " << i.first;

}

int main() {

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

map m;

for(int i=0; i < 10; i++) {

m[i]=t[i];

}

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

return 0;

}

Program outputs:


A.

10 5 9 6 2 4 7 8 3 1


B.

0 1 2 3 4 5 6 7 8 9


C.

9 8 7 6 5 4 3 2 1 0


D.

1 3 8 7 4 2 6 9 5 10


E.

compilation error


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.