Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q14 of 15
C - Input and Output
Identify the error in the following code snippet:
char name[10];
scanf("%c", name);
ANo error, code is correct
BUse &name instead of name
CUse %d instead of %c
DUse %s instead of %c to read string
Step-by-Step Solution
Solution:
  1. Step 1: Understand scanf format specifiers

    %c reads a single character, but name is an array for a string.
  2. Step 2: Correct specifier for string input

    To read a string into name, use %s which reads until whitespace.
  3. Final Answer:

    Use %s instead of %c to read string -> Option D
  4. Quick Check:

    String input needs %s in scanf [OK]
Quick Trick: Use %s to read strings with scanf [OK]
Common Mistakes:
  • Using %c to read strings
  • Forgetting & with non-array variables
  • Using %d for characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes