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 CPA-21-02 Exam - Topic 1 Question 46 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 46
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() {

float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2;

cout << i;

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Krissy
1 day ago
The order of operations makes it 1.
upvoted 0 times
...
Rutha
7 days ago
Wait, really? I thought it would be 0!
upvoted 0 times
...
Stefania
12 days ago
Definitely prints 1, no doubt about it.
upvoted 0 times
...
Alethea
17 days ago
I thought it would be 0.5, but I guess not!
upvoted 0 times
...
Otis
22 days ago
It prints: 1
upvoted 0 times
...
Ollie
27 days ago
Definitely D. The floating-point division ensures that the final result is 0.5, not some integer value.
upvoted 0 times
...
Sherly
1 month ago
D is the correct answer. The floating-point division operations preserve the decimal precision, resulting in the output 0.5.
upvoted 0 times
...
Candra
1 month ago
Haha, this is a classic trick question. The answer is clearly D, 0.5. Who would've thought that floating-point arithmetic could be so tricky?
upvoted 0 times
...
Jeniffer
1 month ago
I think the answer is B. The expression simplifies to 1 after the integer division operations.
upvoted 0 times
...
Nilsa
2 months ago
The answer is D. The expression 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2 evaluates to 0.5.
upvoted 0 times
...
Eladia
2 months ago
I thought it would print 0.5, but now I'm second-guessing if the float type changes anything in the calculations.
upvoted 0 times
...
Weldon
2 months ago
I feel like this could print 0 because of how the divisions work out, but I can't recall the exact calculations.
upvoted 0 times
...
Elke
2 months ago
I agree, the calculations seem to lead to that.
upvoted 0 times
...
Marsha
2 months ago
I remember a similar question where division and multiplication were involved, and it ended up being 1. Maybe that's the case here too?
upvoted 0 times
...
Roxane
2 months ago
I think it prints: 0.5.
upvoted 0 times
...
Chandra
3 months ago
I think the order of operations might affect the result, but I'm not entirely sure how it works with floats.
upvoted 0 times
...
Carry
3 months ago
I've got a strategy - I'll work out the math by hand first, then test it in the code to see if I'm right.
upvoted 0 times
...
Alyce
4 months ago
I'm a bit confused by the mix of floats and integers. I'll need to double-check my understanding of how those interact.
upvoted 0 times
...
Muriel
4 months ago
Okay, let me think this through. I'm going to focus on the math first and then see how the output gets printed.
upvoted 0 times
...
Stevie
4 months ago
Hmm, this looks like it might involve some integer division. I'll need to be careful with that.
upvoted 0 times
...
Jenise
4 months ago
I'm not sure about this one. The order of operations could be tricky, but I think I'll try to work it out step-by-step.
upvoted 0 times
Santos
3 months ago
I’m going with 2.
upvoted 0 times
...
Abel
3 months ago
I believe it will be 0.
upvoted 0 times
...
...

Save Cancel