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 7 Question 89 Discussion

Actual exam question for C++ Institute's CPP exam
Question #: 89
Topic #: 7
[All CPP Questions]

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

#include

#include

#include

#include

#include

using namespace std;

int main(){

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

vector v(t, t+10);

map m;

for(vector::iterator i=v.begin(); i!=v.end(); i++) {

stringstream s; s<<*i<<*i; m.insert(pair(*i,s.str()));

}

for(map::iterator i=m.begin();i!= m.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: E

Contribute your Thoughts:

Aretha
20 days ago
Haha, are they trying to trick us? This seems too straightforward to be the right answer.
upvoted 0 times
...
Tom
1 months ago
Wait, what? I thought I had this figured out, but now I'm second-guessing myself. Better read the code again.
upvoted 0 times
Donte
19 days ago
User 2: It looks like the program is inserting each element twice into the map.
upvoted 0 times
...
Charlene
26 days ago
User 1: The code is inserting elements into a map based on the vector values.
upvoted 0 times
...
...
Ozell
1 months ago
Aha, I know this one! Gotta love those stringstreams and map insertions.
upvoted 0 times
Pearly
13 days ago
User 2: I think the program will output: 6
upvoted 0 times
...
Elli
1 months ago
User 1: What do you think the program will output?
upvoted 0 times
...
...
Janet
2 months ago
I'm not sure, but I think the program will output 6 7.
upvoted 0 times
...
Celia
2 months ago
I believe the program will output 5 7.
upvoted 0 times
...
Carmen
2 months ago
Hmm, this looks like a classic C++ question. I'll have to think through the logic carefully.
upvoted 0 times
Lawanda
24 days ago
The program outputs: 0 00 1 11 2 22 3 33 4 44 5 55 6 66 7 77 8 88 9 99
upvoted 0 times
...
Lawanda
1 months ago
I think the program outputs: 6 6 7 7 2 2 1 1 4 4 5 5 6 6 7 7 9 9 8 8 0 0
upvoted 0 times
...
...
Janet
2 months ago
I think the program will output 6.
upvoted 0 times
...

Save Cancel