Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA-21-02 Topic 1 Question 39 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 39
Topic #: 1
[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 = 1;

if (i++==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Basilia
2 days ago
Haha, this is a classic trick question! The right answer is B, because the post-increment operator `i++` returns the original value of `i`, which is 1, and then increments it. So the output is 2, not 1.
upvoted 0 times
...
Regenia
12 days ago
I think the correct answer is B. The `if (i++==1)` condition evaluates to true, and the `cout << i;` statement prints the incremented value of `i`, which is 2.
upvoted 0 times
...
Deane
13 days ago
The output is obviously 2, since the post-increment operator `i++` returns the original value of `i` before incrementing it.
upvoted 0 times
...
Tegan
1 months ago
I think it prints 2 because the post-increment operator is used.
upvoted 0 times
...
Freeman
1 months ago
I'm not sure, but I think it's A.
upvoted 0 times
...
Keshia
1 months ago
I believe it prints 2.
upvoted 0 times
...
Brock
1 months ago
I think the answer is B.
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