Input / Output in C Language Skill UP
  • Twitter
  • Facebook
  • Snapchat
  • Instagram

Test Your Skill on Input / Output in C Language

In this article, let's test — or analyse — your skill on how input and output are used in the C programming language. We will study some MCQ (Multiple-Choice Questions) and FAQ (Frequently Asked Questions) covering the standard I/O library functions.

📑 On this page:
  • MCQ — Input / Output in C
  • Q1. The odd one out
  • Q2. Return type of getchar()
  • Q3. Formatted I/O functions
  • Q4. Reading a character from stdin
  • Q5. Writing a character — putc()
  • Q6. Not a standard I/O function
  • Frequently Asked Questions
📚 What you'll practice on this page:
  • The difference between formatted and unformatted I/O functions
  • The return types of getchar(), putchar(), putc() and why they are int
  • Which functions read from stdin and which write to stdout
  • Why print() is not a C function
  • When to use printf/scanf and when to prefer getchar/putchar

Every interactive C program uses at least one input function and at least one output function. The C standard library provides two families: the formatted family (printf, scanf) and the unformatted family (getchar, putchar, gets, puts, getc, putc). The six questions below test whether you can tell them apart, and whether you know the return types — which matter far more than beginners expect.

MCQ — Input / Output in C

1. Which one of the following is the odd one out?

  • a. printf()
  • b. putchar()
  • c. scanf()
  • d. puts()
Answer: c. scanf()
printf(), putchar() and puts() all write text to the console. scanf() is the odd one because it reads from the console and stores the input in a variable.

2. What is the return type of getchar()?

  • a. char
  • b. int
  • c. char*
  • d. Reading a character does not require a return type
  • e. Return type depends on the compiler
  • f. EOF
  • g. All of the above
Answer: b and f — int, returning EOF on error.
getchar() reads a character from standard input (stdin, i.e. the keyboard) and returns it as an int, or returns EOF if an error or end-of-file occurs. Returning int rather than char is essential: it lets getchar() return all 256 possible character values plus a distinct EOF value, which char alone could not represent.

3. Which one of the following are formatted input/output functions?

  • a. printf() and scanf()
  • b. printf() and print()
  • c. getchar() and putchar()
  • d. gets() and puts()
  • e. getc() and putc()
Answer: a. printf() and scanf()
In the list given above, only printf() and scanf() belong to the category of formatted I/O functions — they take a format string ("%d", "%lf", …) that tells them how to convert the data. All the other functions listed are unformatted: they read or write raw characters or strings without any conversion specification.

4. Which one of the following functions reads a character from standard input (the keyboard)?

  • a. printf()
  • b. print()
  • c. getchar()
  • d. puts()
  • e. putc()
Answer: c. getchar()
getchar() reads a single character from the standard input stream (stdin) — regardless of what that character is — and returns it to the program. The other functions in the list write to output: printf and puts to stdout, putc to any output stream. print() is not a C function at all.

5. Which one of the following functions writes a character to any output stream and returns an int?

  • a. printf()
  • b. print()
  • c. getchar()
  • d. puts()
  • e. putc()
Answer: e. putc()
The return type of putc() is int. It returns the character written, cast from unsigned char to int, or EOF on error. Because EOF has the value -1 and cannot be represented as an unsigned char, the return type must be int — that is how putc() can signal both success and failure through a single return value.

6. Which one of the following is not a standard formatted input or output function in C language?

  • a. printf()
  • b. print()
  • c. getchar()
  • d. puts()
  • e. putc()
Answer: b. print()
The print() function does not exist in the C programming language. All the other entries in the list are inbuilt functions available in the C standard library — printf, getchar, puts and putc.

Frequently Asked Questions

❓ Quick Viva Questions & Answers

Q1. What is the difference between formatted and unformatted I/O?

Formatted I/O functions (printf, scanf) take a format string that specifies how each value should be converted between its binary representation and text. Unformatted I/O functions (getchar, putchar, gets, puts, getc, putc) read or write raw characters or strings without any conversion specifier.

Q2. Why is the return type of getchar() an int and not a char?

Because getchar() must be able to return all 256 possible byte values and a distinct EOF indicator. A char cannot represent both — especially if char is signed, one valid character value would collide with EOF (-1). Returning int gives 257 distinct values to work with, so EOF is unambiguous.

Q3. What is EOF, and what value does it have?

EOF stands for End Of File. It is a macro defined in <stdio.h>, usually as #define EOF (-1). Input functions return EOF when they reach the end of the stream or encounter an error. On the keyboard, Ctrl+D (Linux/macOS) or Ctrl+Z followed by Enter (Windows) signals end-of-file.

Q4. What is the difference between putchar() and putc()?

putchar(c) writes the character c to stdout and is usually implemented as a macro. putc(c, stream) writes c to any output stream (a file, for example) and is a genuine function. Both return an int — the character written on success, or EOF on failure.

Q5. Is print() really not a C function?

Correct — there is no standard C function named print(). Many other languages (Python, JavaScript, Go) have a print builtin, which is why beginners sometimes carry the name into C. In C, the output function is printf().

Q6. Which I/O function should I prefer for reading a single character?

Use getchar() when you want a quick, unformatted read from stdin. Use scanf(" %c", &ch) when you need formatted reading (and remember the leading space in the format string to skip whitespace — otherwise scanf will happily consume leftover newlines from previous input).

Q7. Why does the C standard keep both formatted and unformatted functions?

Efficiency and control. Unformatted functions are lighter — a single character read or write needs no format parsing. Formatted functions are convenient but carry overhead. A high-performance parser might use getchar() in a loop, while an ordinary application would use printf/scanf for readability.

📖 Related Tutorials

  • Basic Input / Output Statements in C
  • Simple C Programs
  • Arithmetic Operators
  • All Introduction-to-C Assignments
  • Introduction to C — FAQ
  • Introduction to C — MCQ

Previous Topic: >> Simple C Programs  ||  Next Topic: >> Arithmetic Operators


C Language

  • Home
  • Why C Language
  • History of C Language
  • Applications of C Language
  • Introduction To C
    • What is Program?
    • Structure of C Program
    • Working Of C Program
    • CHARACTER SET
    • VARIABLES AND IDENTIFIERS
    • BUILT-IN DATA TYPES
    • OPERATORS AND EXPRESSIONS
    • CONSTANTS AND LITERALS
    • SIMPLE ASSIGNMENT STATEMENT
    • BASIC INPUT/OUTPUT STATEMENT
    • SIMPLE 'C' PROGRAMS
    • Assignments
  • Operators in C Programming
    • Arithmetic Operators
    • Assignment Operators
    • Increment and Decrement Operators
    • Relational Operators
    • Logical Operators
    • Bitwise Operators
    • Other Operators
    • Assignments
  • CONDITIONAL STATEMENTS
    • DECISION MAKING WITHIN A PROGRAM
    • CONDITIONS
    • IF STATEMENT
    • IF-ELSE STATEMENT
    • IF-ELSE LADDER
    • NESTED IF-ELSE
    • SWITCH CASE
    • Assignments
  • LOOPS STATEMENTS
    • Introduction to Loops
    • GO TO Statement
    • Do while Loop
    • While Loop
    • Nested While Loop
    • Difference Between While and Do while
    • Difference Between Goto and loop
    • While loop assignments
    • C FOR Loop
    • C For loop examples
    • Nested for loop
    • Nested for loop examples
    • Infinite while Loops
    • Infinite for Loops
    • Continue in Loops
    • break in Loops
    • Difference while do..while & for
    • Assignments
  • Arrays
    • One Dimensional Array
    • Declaring 1D Arrays
    • Initialization of 1D arrays
    • Accessing element of 1D Array
    • Read and Display 1D Arrays
    • Two Dimensional Arrays
    • Declare 2D Arrays
    • Read and Display 2D Arrays
    • Assignments/Examples
  • Functions
    • Introduction
    • Need For User-Defined Function
    • Multiple Function Program
    • Modular Programming
    • Elements Of User Defined Function
    • Function Definition
    • Function Declaration
    • Types of functions
    • Nesting of Function
    • Recursion
    • Passing Array To Functions
    • Scope, Visibility and Lifetime of Variables
    • Assignments
  • Structure
    • Introduction
    • Array vs Structure
    • Defining Structure
    • Declaring Structure Variables
    • Type Defined Structure
    • Accessing Structure Members
    • Structure Initialization
    • Copying & Comparing Structure Variables
    • Array of Structure
    • Arrays Within Structure
    • Structures Within Structures
    • Structures and Functions
    • Structure Examples/Assignments
  • Union
    • Define Union
    • Create and use Union
    • Difference Between Structure and Union
    • Union Examples
    • Union FAQ
  • Pointers
    • What Are Pointers In C?
    • How Do We Use Pointers In C?
    • Declaration Of A Pointer
    • The Initialization Of A Pointer
    • Syntax Of Pointer Initialization
    • Use Of Pointers In C
    • The Pointer To An Array
    • The Pointer To A Function
    • The Pointer To A Structure
    • Types Of Pointers
    • The Null Pointer
    • The Void Pointer
    • The Wild Pointer
    • The Near Pointer
    • The Huge Pointer
    • The Far Pointer
    • Dangling pointer
    • Accessing Pointers — Indirectly And Directly
    • Pros Of Using Pointers In C
    • Cons Of Pointers In C
    • Applications Of Pointers In C
    • The & Address Of Operator In C
    • How To Read The Complex Pointers In C?
    • Practice Problems On Pointers
  • File Processing
    • File Handling In C
    • Types Of Files In C
    • Operations Done In File Handling
    • File Examples
    • Binary Files
    • Count words, lines in a file
    • Copy files
    • Update File
    • Count vowels in a file
  • Preprocessor
    • Macro substitution division
    • File Inclusion
    • Conditional Compilation
    • Other directives
    • Examples
  • Dynamic Memory Allocation
    • malloc
    • calloc
    • free
    • realloc
    • Examples
  • Storage Classes
  • Graphics
  • Frequently Asked Interview Questions (FAQ)
    • Introduction To C FAQ
    • Operators FAQ
    • Conditional Statements FAQ
    • Loops FAQ
    • Arrays FAQ
    • Function FAQ
    • Structure FAQ
    • Pointers FAQ
    • Files FAQ
    • Storage classes FAQ
    • Dynamic Memory FAQ
  • Programs/Assignments
    • Introduction To C
    • Operators
    • Conditional Statements
    • Loops
    • Arrays
    • Function
    • Structure
    • Pointers
    • Files
    • Storage classes
    • Dynamic Memory
  • Case Studies
  • Multiple Choice Questions
    • Introduction To C MCQ
    • Operators MCQ
    • Conditional Statements MCQ
    • Loops MCQ
    • Arrays MCQ
    • Function MCQ
    • Structure MCQ
    • Pointers MCQ
    • Files MCQ
    • Storage classes MCQ
    • Dynamic Memory MCQ
    • More MCQ

Get in touch

  • tech2dsm@gmail.com

© Sankalan Data Technologies. All rights reserved.