Bird
0
0

What is the correct way to read a character and an integer from user input in C?

easy📝 Conceptual Q2 of 15
C - Input and Output
What is the correct way to read a character and an integer from user input in C?
Achar c; int n; scanf("%c %d", &c, &n);
Bchar c; int n; scanf("%d %c", &n, &c);
Cchar c; int n; scanf("%c %d", c, n);
Dchar c; int n; scanf("%d %c", n, c);
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct format specifiers and order

    To read a character then an integer, use "%c %d" in scanf.
  2. Step 2: Use addresses of variables in scanf

    Variables must be passed with & to store input correctly.
  3. Final Answer:

    Uses correct format and addresses for reading char and int. -> Option A
  4. Quick Check:

    Correct format and & usage = char c; int n; scanf("%c %d", &c, &n); [OK]
Quick Trick: Match format specifiers order with variables [OK]
Common Mistakes:
  • Swapping format specifiers
  • Missing & in scanf
  • Passing variables instead of addresses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes