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 a = 10;
float b = 5.5;
printf("%d", (int)b + a);
A15
B10
C5
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand type casting and addition

    The float variable b is cast to int, so 5.5 becomes 5.
  2. Step 2: Calculate the sum

    Adding casted 5 and a (10) gives 15.
  3. Final Answer:

    15 -> Option A
  4. Quick Check:

    Cast float to int then add = 15 [OK]
Quick Trick: Casting float to int drops decimals [OK]
Common Mistakes:
  • Expecting 15.5 output
  • Ignoring cast to int
  • Thinking code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes