Bird
0
0

What is the output of this C code?

medium📝 Predict Output Q13 of 15
C - Operators and Expressions
What is the output of this C code?
int x = 5;
int y = (x > 3) ? 10 : 20;
printf("%d", y);
A10
B20
C5
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition (x > 3)

    Since x is 5, 5 > 3 is true.
  2. Step 2: Apply ternary operator

    Because condition is true, y is assigned 10.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    (5 > 3) ? 10 : 20 = 10 [OK]
Quick Trick: Check if condition is true, then pick first value [OK]
Common Mistakes:
  • Choosing the false value by mistake
  • Confusing variable values
  • Thinking it causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes