New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPP Exam - Topic 7 Question 2 Discussion

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

listv(t, t+10);

set s1(v.begin(),v.end());

if (s1.count(3) == 2) {

s1.erase(3);

}

for(set::iterator i=s1.begin();i!= s1.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
Gerald
4 months ago
No compilation errors here!
upvoted 0 times
...
Arleen
4 months ago
I thought it would show duplicates!
upvoted 0 times
...
Ellsworth
4 months ago
Wait, how can count(3) be 2?
upvoted 0 times
...
Christiane
4 months ago
Definitely outputs 1 2 4 5!
upvoted 0 times
...
Mabel
5 months ago
The set will only keep unique values.
upvoted 0 times
...
King
5 months ago
I'm feeling pretty confident about this one. The requirement to run the new version alongside the old version before switching over points directly to a blue/green deployment strategy. Let's go with that.
upvoted 0 times
...
Anabel
5 months ago
Hmm, this looks like a tricky one. I'll need to carefully read through the error message and the options to figure out the best approach.
upvoted 0 times
...

Save Cancel