Bird
0
0

What is the mistake in the following code snippet?

medium📝 Debug Q6 of 15
C - Input and Output
What is the mistake in the following code snippet?
int value;
printf("Input a value: ");
scanf("%d", value);
printf("Value is %d", value);
AThe format specifier '%d' is incorrect for an integer variable.
BThe variable 'value' should be passed by address using &value in scanf.
CThe printf statement should use '%f' instead of '%d'.
DThe variable 'value' should be declared as a float.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze scanf usage

    scanf requires the address of the variable to store the input value.
  2. Step 2: Identify the error

    The code passes 'value' instead of '&value', so scanf cannot store the input correctly.
  3. Final Answer:

    The variable 'value' should be passed by address using &value in scanf. -> Option B
  4. Quick Check:

    Check if & is used with variables in scanf [OK]
Quick Trick: Always use & with variables in scanf [OK]
Common Mistakes:
  • Forgetting the & operator in scanf
  • Using wrong format specifier for variable type
  • Passing variable instead of its address

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes