Bird
0
0

What will be the output of the following code if the user inputs 42?

medium📝 Predict Output Q4 of 15
C - Input and Output
What will be the output of the following code if the user inputs 42?
int num;
printf("Enter number: ");
scanf("%d", &num);
printf("You entered: %d", num);
AYou entered: %d
BYou entered: 0
CYou entered: 42
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand input and scanf usage

    The code reads an integer input into num using scanf("%d", &num).
  2. Step 2: Output the stored value

    The printf prints the value of num with the correct format specifier %d.
  3. Final Answer:

    You entered: 42 -> Option C
  4. Quick Check:

    Correct input and output format = expected output [OK]
Quick Trick: Use &variable with %d to read int correctly [OK]
Common Mistakes:
  • Forgetting & in scanf
  • Using wrong format specifier in printf
  • Expecting literal %d output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes