Bird
0
0

Which of the following is the correct way to read a float variable named price using scanf?

easy📝 Conceptual Q2 of 15
C - Input and Output
Which of the following is the correct way to read a float variable named price using scanf?
Ascanf("%lf", &price);
Bscanf("%f", &price);
Cscanf("%f", price);
Dscanf("%d", price);
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct format specifier for float

    The format specifier for float is %f, and the variable address must be passed.
  2. Step 2: Check pointer usage

    The variable's address must be passed using &price, not just price.
  3. Final Answer:

    scanf("%f", &price); -> Option B
  4. Quick Check:

    Float input uses %f and &variable [OK]
Quick Trick: Use %f with &variable for float input [OK]
Common Mistakes:
  • Using %d for float input
  • Passing variable instead of its address
  • Using %lf for float (only for double)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes