LearnFrenzy
Sign in Take a free test

Control Instructions · Control Instructions MCQ · Question 9

Type of cond ? 1 : 2.0 in C Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the type of the expression flag ? 1 : 2.0?

  • A int
  • B double Correct
  • C It depends on flag
  • D float
Correct Answer: Option B

The conditional operator has one type, worked out at compile time from both branches with the usual arithmetic conversions: int and double give double. So even when flag is true the result is 1.0.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links