BlackFriday 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 CPA-21-02 Topic 7 Question 27 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 27
Topic #: 7
[All CPA-21-02 Questions]

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

#include

using namespace std;

int main()

{

int i = 4;

while(i >= 0) {

cout<

i??;

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

Makeda
26 days ago
Hmm, I think the answer is B. The post-decrement operator will cause the value of i to be printed first, and then it will be decremented. So the output should be '3210'.
upvoted 0 times
...
Iluminada
27 days ago
Haha, that's a classic one! I remember getting tripped up by the post-decrement operator before. This is going to be a good test of our attention to detail.
upvoted 0 times
Therese
3 days ago
User 3: None of these
upvoted 0 times
...
Reta
5 days ago
User 2: I think it prints: '3210'
upvoted 0 times
...
Domitila
12 days ago
It prints: '3210?1'
upvoted 0 times
...
...
Magnolia
1 months ago
I'm not sure, but I think it will print '3210'
upvoted 0 times
...
Harley
2 months ago
Wait, what's that i-- thing doing? Isn't that supposed to decrement the value of i?
upvoted 0 times
...
Donte
2 months ago
Okay, let's think this through. The code is incrementing the value of i by 1 in each iteration, so it should print the numbers in descending order, right?
upvoted 0 times
Noah
12 days ago
C) It prints: '3210?1'
upvoted 0 times
...
Tom
14 days ago
None of these
upvoted 0 times
...
Meaghan
16 days ago
B) It prints: '3210'
upvoted 0 times
...
Samira
20 days ago
I think it prints: ''3210''
upvoted 0 times
...
Horace
28 days ago
A) It prints: '43210'
upvoted 0 times
...
Louis
29 days ago
No, it prints: ''3210''
upvoted 0 times
...
Pa
1 months ago
It prints: ''3210?1''
upvoted 0 times
...
...
Jovita
2 months ago
I agree with Gerardo, because the loop starts at 4 and goes down to 0
upvoted 0 times
...
Gerardo
2 months ago
I think it will print '3210'
upvoted 0 times
...

Save Cancel