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

Posted by Lindsey on Nov 01, 2025 at 01:22 AM

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;

}

Suggested Answer: B

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
28 comments · newest first
IR
Ira 7 months ago
No way, it should definitely be 0.5 based on the operations.
DE
Della 7 months ago
But isn't it possible it rounds down to 0?
KR
Krissy 8 months ago
The order of operations makes it 1.
RU
Rutha 8 months ago
Wait, really? I thought it would be 0!
ST
Stefania 8 months ago
Definitely prints 1, no doubt about it.
AL
Alethea 8 months ago
I thought it would be 0.5, but I guess not!
OT
Otis 8 months ago
It prints: 1
OL
Ollie 8 months ago
Definitely D. The floating-point division ensures that the final result is 0.5, not some integer value.
SH
Sherly 9 months ago
D is the correct answer. The floating-point division operations preserve the decimal precision, resulting in the output 0.5.
CA
Candra 9 months 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?
JE
Jeniffer 9 months ago
I think the answer is B. The expression simplifies to 1 after the integer division operations.
NI
Nilsa 9 months ago
The answer is D. The expression 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2 evaluates to 0.5.
EL
Eladia 9 months ago
I thought it would print 0.5, but now I'm second-guessing if the float type changes anything in the calculations.
WE
Weldon 10 months ago
I feel like this could print 0 because of how the divisions work out, but I can't recall the exact calculations.
EL
Elke 10 months ago
I agree, the calculations seem to lead to that.
MA
Marsha 10 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?
RO
Roxane 10 months ago
I think it prints: 0.5.
CH
Chandra 11 months ago
I think the order of operations might affect the result, but I'm not entirely sure how it works with floats.
CA
Carry 11 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.
AL
Alyce 11 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.
MU
Muriel 11 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.
ST
Stevie 12 months ago
Hmm, this looks like it might involve some integer division. I'll need to be careful with that.
JE
Jenise 12 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.
AA
Aaron 6 months ago
↳ replying to Jenise
The order of operations is confusing!
RA
Rasheeda 6 months ago
↳ replying to Jenise
I’m leaning towards 0.5.
DO
Donette 7 months ago
↳ replying to Jenise
I think it will print 1.
SA
Santos 10 months ago
↳ replying to Jenise
I’m going with 2.
AB
Abel 11 months ago
↳ replying to Jenise
I believe it will be 0.
0/2000 characters

Save Cancel