Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
C - Input and Output
What is wrong with this code?
char name[20];
printf("Enter name: ");
scanf("%c", &name);
AUsing %c instead of %s for string input
BMissing & before name
CArray size too small
DNo error
Step-by-Step Solution
Solution:
  1. Step 1: Check format specifier for string input

    To read a string, %s should be used, not %c.
  2. Step 2: Confirm pointer usage

    Passing &name is incorrect; for arrays, just name is used with %s.
  3. Final Answer:

    Using %c instead of %s for string input -> Option A
  4. Quick Check:

    Use %s for strings, not %c [OK]
Quick Trick: Use %s with array name (no &) for strings [OK]
Common Mistakes:
  • Using %c to read strings
  • Passing &array name instead of array
  • Confusing char and string input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes