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
1 months 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
Launa
4 days ago
Yeah, it's definitely a compilation error.
upvoted 0 times
...
Honey
8 days ago
I agree, this code looks like it will give a compilation error.
upvoted 0 times
...
Hayley
9 days ago
I think the output will be compilation error.
upvoted 0 times
...
...
Nobuko
2 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
Jesusita
11 days ago
Yeah, that's a mistake in the code. It should be `m.find(5)` to search for the key 5 in the map.
upvoted 0 times
...
Nickie
22 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
1 months ago
You're right, using `find()` on a `map` is incorrect.
upvoted 0 times
...
...
Joesph
2 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
Georgeanna
11 days ago
The correct answer is 4.
upvoted 0 times
...
Cherry
28 days ago
Actually, it will be 10.
upvoted 0 times
...
France
1 months ago
No, it will be 4.
upvoted 0 times
...
Natalie
1 months 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
1 months ago
B) 4
upvoted 0 times
...
Karan
2 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
20 days ago
The output will be a compilation error.
upvoted 0 times
...
Giovanna
1 months ago
So, what will be the output then?
upvoted 0 times
...
Elli
2 months ago
Oh, I see. The find() function is used to search for a key, not a value.
upvoted 0 times
...
Cherry
2 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
3 months ago
I think the answer is D) compilation error.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77