Bird
0
0

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

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

    The ternary operator syntax is condition ? value_if_true : value_if_false;
  2. Step 2: Match with options

    condition ? value_if_true : value_if_false; matches the correct syntax exactly.
  3. Final Answer:

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

    Correct ternary syntax = condition ? value_if_true : value_if_false; [OK]
Quick Trick: Remember: ? then true value, : then false value [OK]
Common Mistakes:
  • Swapping true and false parts
  • Misplacing colon and question mark
  • Using commas instead of colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes