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
3 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
3 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
2 months ago
I agree with you, option D seems like the chaotic choice.
upvoted 0 times
...
Emily
2 months ago
I'm going with option B, the output will be 11.
upvoted 0 times
...
Helaine
3 months ago
I think it's option C, the output will be ?10.
upvoted 0 times
...
...
Louisa
4 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
2 months ago
I agree with you, option C seems like the correct answer.
upvoted 0 times
...
Rhea
2 months ago
I'm not sure about that. I believe it will be 11.
upvoted 0 times
...
Candra
3 months ago
That's a tricky one. I think the output will be 10.
upvoted 0 times
...
...
Marva
4 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
4 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
4 months ago
I believe the output will be 11.
upvoted 0 times
...
Shawna
4 months ago
I think the output will be 10.
upvoted 0 times
...

Save Cancel