Bird
0
0

Which of the following is the correct way to read an integer variable num using scanf?

easy📝 Syntax Q12 of 15
C - Input and Output
Which of the following is the correct way to read an integer variable num using scanf?
Ascanf("%s", &num);
Bscanf("%d", num);
Cscanf("%f", &num);
Dscanf("%d", &num);
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct format specifier for integer

    Use %d to read an integer.
  2. Step 2: Use the address operator for variables

    Use &num to pass the address of the variable to scanf.
  3. Final Answer:

    scanf("%d", &num); -> Option D
  4. Quick Check:

    Integer input needs %d and &variable [OK]
Quick Trick: Use & before variable except arrays [OK]
Common Mistakes:
  • Omitting & before variable
  • Using wrong format specifier like %f or %s
  • Passing variable instead of its address

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes