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 1 Question 103 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 103
Topic #: 1
[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[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };

map m;

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

m[i]=t[i];

}

map::iterator it = find(m.begin(), m.end(), 5);

cout<first;

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Dulce
16 days ago
I bet the output will be a rude message to the person who wrote this question. Seriously, who comes up with these tricky questions?
upvoted 0 times
...
Nobuko
1 months ago
Wait, why are we using `find()` on a `map` when we should be using `m.find(5)`? Developers these days, I tell you.
upvoted 0 times
Nickie
7 days ago
I think the correct way is to use `m.find(5)` instead of `find(m.begin(), m.end(), 5)`.
upvoted 0 times
...
Rasheeda
26 days ago
You're right, using `find()` on a `map` is incorrect.
upvoted 0 times
...
...
Joesph
1 months ago
I think the output will be 10. The `map` container stores key-value pairs, and we're trying to find the value associated with the key 5, which should be 10.
upvoted 0 times
Cherry
13 days ago
Actually, it will be 10.
upvoted 0 times
...
France
27 days ago
No, it will be 4.
upvoted 0 times
...
Natalie
29 days ago
I think the output will be 10.
upvoted 0 times
...
...
France
2 months ago
The output will be 4. The `find()` function will return an iterator pointing to the element with a key of 5, and we're trying to access the `first` member of that iterator, which is the key, not the value.
upvoted 0 times
Leana
26 days ago
B) 4
upvoted 0 times
...
Karan
1 months ago
A) 5
upvoted 0 times
...
...
Launa
2 months ago
The code will result in a compilation error. The `find()` function in the `map` container is used to search for a key, not a value.
upvoted 0 times
Gearldine
5 days ago
The output will be a compilation error.
upvoted 0 times
...
Giovanna
16 days ago
So, what will be the output then?
upvoted 0 times
...
Elli
1 months ago
Oh, I see. The find() function is used to search for a key, not a value.
upvoted 0 times
...
Cherry
1 months ago
You will get a compilation error.
upvoted 0 times
...
...
Billy
2 months ago
I also think it's D) compilation error, because find() function requires a specific key to search for in a map.
upvoted 0 times
...
Stevie
2 months ago
I agree with Santos, because the find() function cannot be used with map containers.
upvoted 0 times
...
Santos
2 months ago
I think the answer is D) compilation error.
upvoted 0 times
...

Save Cancel