A

Admin • 828.03K Points
Coach

Q. What is a standard library function to read 1 char at a time?

  • (A) putchar()
  • (B) printf()
  • (C) getchar()
  • (D) write()
  • Correct Answer - Option(C)
  • Views: 21
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

In C language, getchar() is a standard library function used to read a single character from the standard input (keyboard).

Usage of getchar()

#include <stdio.h>

int main() {
char ch;
printf("Enter a character: ");
ch = getchar(); // Reads a single character
printf("You entered: %c
", ch);
return 0;
}

Why Not the Other Options?

  • (A) putchar() → Outputs (prints) a single character, does not read.
  • (B) printf() → Prints formatted output, does not read characters.
  • (D) write() → A low-level system call, not a standard library function for character input.

Thus, (C) getchar() is the correct answer!

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.