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 CPP Exam - Topic 7 Question 60 Discussion

What will happen when you attempt to compile and run the following code?#include #include #include using namespace std;template void print(T start, T end) {while (start != end) {std::cout
D) compilation error
A) 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
B) 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1
C) 10 9 8 7 6 5 4 3 2 1 and unpredictable sequence of number range 1 to 10

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

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

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

#include

#include

#include

using namespace std;

template void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

int main(){

vectorv;

set s;

for(int i=10; i>0; i??) {

v.push_back(i);

s.push_back(i);

}

print(v.begin(), v.end()); print(s.begin(), s.end());cout<

return 0;

}

The output will be:

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

0/2000 characters
Noble
10 months ago
I’m surprised it doesn’t compile at all!
upvoted 0 times
...
Theodora
10 months ago
The output should be D for sure.
upvoted 0 times
...
Myrtie
10 months ago
Wait, really? I thought sets could add elements like vectors.
upvoted 0 times
...
Delfina
10 months ago
Totally agree, sets don’t have push_back!
upvoted 0 times
...
Sherly
11 months ago
Looks like a compilation error due to push_back on set.
upvoted 0 times
...
Marylin
11 months ago
I’m not sure, but I feel like the output could be unpredictable because of the set. Maybe option C?
upvoted 0 times
...
Janey
11 months ago
This question seems similar to one we practiced where we had to identify errors in code. I’m leaning towards option D for that reason.
upvoted 0 times
...
Renea
11 months ago
I think the loop condition `i??` is definitely wrong, which might lead to a compilation error.
upvoted 0 times
...
Tony
11 months ago
I remember something about the `push_back` method, but I thought it was only for vectors, not sets.
upvoted 0 times
...
Keva
11 months ago
Hmm, I'm a bit unsure about this one. The prompt talks about competitive and benchmark data, but I'm not totally clear on how that relates to quality leadership. I'll need to think this through carefully.
upvoted 0 times
...
Steffanie
11 months ago
Okay, let's see... I'm pretty sure the answer is not A or D, so I'll focus on B and C.
upvoted 0 times
...
Jesse
11 months ago
This reminds me of a practice question where we discussed how prompting and fading help with language acquisition. I feel like it's definitely related to stimulus generalization too, but I might be mixing them up.
upvoted 0 times
...

Save Cancel