Cyber Monday 2024! 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 93 Discussion

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

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

#include

#include

#include

using namespace std;

void print(int v) { cout<

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() {

return 10*(1+(start++ %3));

}

};

int main() {

vector v1(10);

generate_n(v1.begin(), 10, Sequence(1));

remove(v1.begin(), v1.end(), 10);

for_each(v1.begin(), v1.end(), print);cout<

return 0;

}

Program outputs:

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

Carin
2 months ago
Wait, is this a trick question? The real answer is to scrap the whole thing and use Python instead. Much less headache.
upvoted 0 times
Bettina
1 months ago
A) 20 30 10 20 30 10 20 30 10 20
upvoted 0 times
...
...
Magda
2 months ago
Hmm, let's see... Is the answer 42? Because that's the answer to everything, right?
upvoted 0 times
...
Jonell
2 months ago
C looks right to me. I mean, what could go wrong with that convoluted `Sequence` struct? It's probably just an elegant and concise way to generate the numbers.
upvoted 0 times
Barbra
1 months ago
C) 20 30 20 30 20 30 20 30 10 20
upvoted 0 times
...
Nina
1 months ago
B) 20 30 20 30 20 30 20
upvoted 0 times
...
Ronnie
1 months ago
A) 20 30 10 20 30 10 20 30 10 20
upvoted 0 times
...
...
Dominic
2 months ago
I'm going with A. Who doesn't love a good old-fashioned off-by-one error? Classic!
upvoted 0 times
...
Rosendo
2 months ago
D, definitely a compilation error! Why would they use `remove()` on a vector when they should be using `erase()`? Rookie mistake.
upvoted 0 times
Mila
26 days ago
D) compilation error
upvoted 0 times
...
Christoper
28 days ago
C) 20 30 20 30 20 30 20 30 10 20
upvoted 0 times
...
Lashunda
29 days ago
B) 20 30 20 30 20 30 20
upvoted 0 times
...
Theola
1 months ago
A) 20 30 10 20 30 10 20 30 10 20
upvoted 0 times
...
...
Carolynn
2 months ago
The correct answer is B. The code generates a sequence of 10 numbers starting from 1 and incrementing by 3, then removes the value 10 from the vector before printing the remaining numbers.
upvoted 0 times
Ellsworth
2 months ago
I see, so the correct answer is B because the code generates a sequence and removes the value 10 from the vector.
upvoted 0 times
...
Richelle
2 months ago
That makes sense, the code removes the value 10 before printing the remaining numbers.
upvoted 0 times
...
Merilyn
2 months ago
B) 20 30 20 30 20 30 20
upvoted 0 times
...
...
Barb
3 months ago
I agree with Junita, D) compilation error makes sense since remove function is not used correctly
upvoted 0 times
...
Junita
3 months ago
I believe it's D) compilation error because there seems to be an issue with the remove function
upvoted 0 times
...
Dorothy
3 months ago
I think the answer is A) 20 30 10 20 30 10 20 30 10 20
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