Bird
0
0

Which of the following is the correct syntax for the ternary operator in C?

easy📝 Syntax Q12 of 15
C - Operators and Expressions
Which of the following is the correct syntax for the ternary operator in C?
Acondition : value_if_true ? value_if_false;
Bcondition ? value_if_true : value_if_false;
Ccondition ? value_if_true, value_if_false;
Dcondition ? (value_if_true : value_if_false);
Step-by-Step Solution
Solution:
  1. Step 1: Recall ternary operator syntax

    The correct syntax is: condition ? value_if_true : value_if_false;
  2. Step 2: Check each option

    condition ? value_if_true : value_if_false; matches the correct syntax exactly; others have misplaced symbols or punctuation.
  3. Final Answer:

    condition ? value_if_true : value_if_false; -> Option B
  4. Quick Check:

    Syntax is condition ? true : false; [OK]
Quick Trick: Remember: question mark before colon in ternary [OK]
Common Mistakes:
  • Swapping question mark and colon
  • Using comma instead of colon
  • Adding extra parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes