Bird
0
0

Identify the error in this C code using the ternary operator:

medium📝 Debug Q14 of 15
C - Operators and Expressions
Identify the error in this C code using the ternary operator:
int a = 10;
int b = 20;
int max = a > b ? a, b;
AMissing colon ':' between values
BIncorrect variable declaration
CNo error, code is correct
DUsing comma instead of colon in ternary
Step-by-Step Solution
Solution:
  1. Step 1: Check ternary operator syntax

    The ternary operator requires a colon ':' between the two possible values.
  2. Step 2: Identify the mistake

    The code uses a comma ',' instead of a colon ':', which is incorrect syntax.
  3. Final Answer:

    Using comma instead of colon in ternary -> Option D
  4. Quick Check:

    Ternary needs ':' not ',' [OK]
Quick Trick: Ternary uses ':' not ',' between values [OK]
Common Mistakes:
  • Using comma instead of colon
  • Forgetting colon entirely
  • Assuming code is correct

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes