Bird
0
0

What is the output of the following C code?

medium📝 Predict Output Q4 of 15
C - Operators and Expressions
What is the output of the following C code?
int x = 8;
x /= 2;
printf("%d", x);
A0
B16
C2
D4
Step-by-Step Solution
Solution:
  1. Step 1: Understand the '/=' operator effect

    'x /= 2;' divides x by 2 and assigns the result back to x. Initially x=8, so x becomes 8/2 = 4.
  2. Step 2: Determine the output of printf

    printf prints the current value of x, which is 4.
  3. Final Answer:

    The output is 4 -> Option D
  4. Quick Check:

    Division assignment result = 4 [OK]
Quick Trick: '/=' divides left by right and assigns [OK]
Common Mistakes:
  • Thinking '/=' multiplies
  • Confusing output with initial value
  • Ignoring integer division

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes