Multiple choice

Which of the following will read a character from the keyboard and store it in the variable c?

  1. c = getc();

  2. getc( &c );

  3. c = getchar( stdin );

  4. getchar( &c )

  5. c = getchar();

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

getchar() reads one character from stdin and returns it as an int (or EOF). Correct usage: c = getchar(). Option A uses getc() without stream argument. Options B and D pass address to getchar (wrong - it takes no arguments). Option C passes stdin to getchar (wrong signature). Only option E is correct.