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 Exam CPA-21-02 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:

Jennifer
18 days 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
20 days 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
...
Louisa
1 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
Candra
3 days ago
That's a tricky one. I think the output will be 10.
upvoted 0 times
...
...
Marva
1 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
2 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
2 months ago
I believe the output will be 11.
upvoted 0 times
...
Shawna
2 months ago
I think the output will be 10.
upvoted 0 times
...

Save Cancel