Bird
0
0

Identify the problem in this code:

medium📝 Debug Q7 of 15
C - Input and Output
Identify the problem in this code:
#include <stdio.h>
int main() {
  int x;
  printf("Enter a number: ");
  scanf("%d", &x);
  printf("You entered %d", x);
  return 0;
}

When run, the prompt does not appear before input is requested. Why?
AVariable x is not declared
Bscanf syntax is wrong
Cprintf format specifier is incorrect
DOutput is buffered; missing fflush(stdout)
Step-by-Step Solution
Solution:
  1. Step 1: Understand output buffering

    printf output may be buffered and not shown immediately before scanf waits for input.
  2. Step 2: Fix buffering issue

    Using fflush(stdout) after printf forces output to display before input.
  3. Final Answer:

    Output is buffered; missing fflush(stdout) -> Option D
  4. Quick Check:

    Use fflush to show prompt before input [OK]
Quick Trick: Use fflush(stdout) to flush output buffer [OK]
Common Mistakes:
  • Blaming scanf syntax
  • Ignoring output buffering
  • Assuming variable declaration error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes