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 3 Question 34 Discussion

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

What is the output of the program given below?

#include

using namespace std;

int main (int argc, const char * argv[])

{

float f=?10.501;

cout<<(int)f;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

0/2000 characters
Wilburn
3 months ago
I agree, it should be 10 after casting!
upvoted 0 times
...
Arthur
3 months ago
Wait, is the output really 11? That seems off.
upvoted 0 times
...
Dominga
3 months ago
Pretty sure it rounds down to 10.
upvoted 0 times
...
Lottie
4 months ago
I think it will output 11 when cast to int.
upvoted 0 times
...
Haley
4 months ago
It's definitely 10.501 as a float.
upvoted 0 times
...
Ligia
4 months ago
I’m leaning towards option D, but I’m confused about the initial float value. Did we cover how to handle floats with a leading question mark?
upvoted 0 times
...
Maryann
4 months ago
This seems similar to a practice question we did last week. I believe it should output 11 because of how rounding works in C++.
upvoted 0 times
...
Howard
4 months ago
I think the output should be the integer part of the float, so maybe it's 10? But I'm not completely confident.
upvoted 0 times
...
Zena
5 months ago
I remember we discussed type casting in class, but I'm not sure how the float will convert to an int here.
upvoted 0 times
...
Roselle
5 months ago
I've got this! The float 10.501 will be truncated to 10 when cast to an int. The output should be 10.
upvoted 0 times
...
German
5 months ago
I'm a bit confused here. Does the type casting round the value or just truncate it? I'll have to double-check the behavior.
upvoted 0 times
...
Daisy
5 months ago
Okay, let me walk through this step-by-step. The float is initialized to 10.501, and then we cast it to an int. I think the output will be 10.
upvoted 0 times
...
Tijuana
5 months ago
Hmm, this looks like a tricky one. I'll need to carefully think through the type casting from float to int.
upvoted 0 times
...
Jennifer
9 months ago
This is a simple case of rounding. The float f is 10.501, and when we cast it to an integer, it should round up to 11. Option B is the correct answer, no doubt about it.
upvoted 0 times
...
Emilio
10 months ago
Haha, the question mark is just there to confuse us. It's a classic trick question! I'm going to go with option D, because who doesn't love a bit of chaos in their code?
upvoted 0 times
Cyndy
8 months ago
I agree with you, option D seems like the chaotic choice.
upvoted 0 times
...
Emily
8 months ago
I'm going with option B, the output will be 11.
upvoted 0 times
...
Helaine
9 months ago
I think it's option C, the output will be ?10.
upvoted 0 times
...
...
Louisa
10 months ago
Wait, why is the float initialized with a question mark? That's not valid syntax! I'm going to go with option C, which seems to make the most sense.
upvoted 0 times
Sherell
8 months ago
I agree with you, option C seems like the correct answer.
upvoted 0 times
...
Rhea
9 months ago
I'm not sure about that. I believe it will be 11.
upvoted 0 times
...
Candra
9 months ago
That's a tricky one. I think the output will be 10.
upvoted 0 times
...
...
Marva
10 months ago
I think the output will be 11. The float f is initialized to 10.501, and when we cast it to an integer, the decimal part gets truncated.
upvoted 0 times
...
Shawna
11 months ago
But since it's casting a float to an int, it will truncate the decimal part, so the output should be 10.
upvoted 0 times
...
Harris
11 months ago
I believe the output will be 11.
upvoted 0 times
...
Shawna
11 months ago
I think the output will be 10.
upvoted 0 times
...

Save Cancel