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 9 Question 120 Discussion

Posted by King on Apr 01, 2026 at 02:25 PM

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout<

return 0;

}

Program outputs:

Suggested Answer: A

Get Premium CPP Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
12 comments · newest first
KA
Kaitlyn 3 months ago
I feel like it might be a compilation error, but I agree with you both.
GA
Gail 3 months ago
Yeah, setprecision(2) rounds it to two decimal places.
JE
Jenifer 3 months ago
I think it outputs 10.126 10.12.
SH
Shelia 3 months ago
It's B for sure, setprecision affects the output.
FE
Felicitas 3 months ago
Wait, why does it round down? That’s weird!
FR
Francesco 4 months ago
Definitely not a compilation error!
KA
Kate 5 months ago
I think it should be 10.126 10.13, right?
DE
Dell 5 months ago
The output will be 10.126 10.12.
QU
Quiana 6 months ago
I’m a bit confused; I thought setprecision only works with fixed notation, but this code doesn’t specify that. Could it lead to a different output?
KA
Kayleigh 6 months ago
I practiced a similar question, and I think the output will show the float with two decimal places, so it might be B.
FR
Francoise 6 months ago
I remember something about setprecision affecting the output, but I can't recall if it rounds or just truncates the number.
LI
Linwood 7 months ago
I think the code should compile fine since there are no syntax errors, but I'm not sure about the output formatting.
0/2000 characters

Save Cancel