Bird
0
0

Which of these best describes the syntax of the ternary conditional operator in Swift?

easy📝 Conceptual Q2 of 15
Swift - Operators and Expressions
Which of these best describes the syntax of the ternary conditional operator in Swift?
Aif condition then valueIfTrue else valueIfFalse
Bcondition ? valueIfTrue : valueIfFalse
Ccondition : valueIfTrue ? valueIfFalse
DvalueIfTrue ? condition : valueIfFalse
Step-by-Step Solution
Solution:
  1. Step 1: Recall the ternary syntax

    The ternary operator syntax is: condition ? valueIfTrue : valueIfFalse.
  2. Step 2: Check each option

    condition ? valueIfTrue : valueIfFalse matches the correct syntax. The other options have incorrect order or keywords.
  3. Final Answer:

    condition ? valueIfTrue : valueIfFalse -> Option B
  4. Quick Check:

    Syntax format = condition ? true : false [OK]
Quick Trick: Remember: question mark after condition, colon after true value [OK]
Common Mistakes:
  • Swapping true and false parts
  • Using if-else keywords
  • Misplacing question mark or colon

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes