Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q4 of 15
C - Variables and Data Types
What will be the output of this C code?
int main() {
    int a = 10;
    int b = 5;
    a = b;
    b = 20;
    printf("%d %d", a, b);
    return 0;
}
A10 20
B10 5
C5 5
D5 20
Step-by-Step Solution
Solution:
  1. Step 1: Trace variable assignments

    Initially, a=10, b=5. Then a = b sets a to 5. Then b = 20 changes b to 20.
  2. Step 2: Determine final values printed

    Prints a and b: a is 5, b is 20.
  3. Final Answer:

    5 20 -> Option D
  4. Quick Check:

    Variable assignment traced correctly = 5 20 [OK]
Quick Trick: Assignment copies value; later changes don't affect previous variables [OK]
Common Mistakes:
  • Assuming a changes when b changes after assignment
  • Confusing initial values with final
  • Mixing variable names in print

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes