---
title: "Formatted vs unformatted I/O"
subject: "Computer Programming"
chapter: 4
key: "semester_1/computer_programming:formatted-vs-unformatted-io"
source: https://www.bctengineer.com/q/semester_1/computer_programming/formatted-vs-unformatted-io
site: BCT Engineering
---

# Formatted vs unformatted I/O

Computer Programming · Chapter 4: Input and Output

- Asked in: 2074 Chaitra, 4 marks; 2070 Chaitra, 4 marks; 2068 Chaitra, 4 marks; 2072 Kartik, 1 marks (asked 4 times)
- Video: [Formatted and Unformatted Input-Output Functions in C Programming Language | Learners Region](https://www.youtube.com/watch?v=t2mBYMdmlms) — Learners Region
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/formatted-vs-unformatted-io
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-4

## Question

What are the differences between formatted and unformatted input/output functions? Write down the syntax and give suitable examples.

## Short answer

Formatted I/O uses format specifiers like %d and %f to control conversion and handle all data types; functions include scanf and printf. Unformatted I/O works with characters and strings as-is, using getchar, putchar, gets, puts, and is simpler. Example: scanf("%d",&age) reads an integer, while ch=getchar() reads a character.

## Answer

**Formatted I/O** functions read or display data according to a format given by the programmer (type, width, precision). **Unformatted I/O** functions read or write a single character or string as it is, without any format specification.

| Formatted | Unformatted |
|---|---|
| Uses format specifiers (`%d`, `%f`, `%c`) | No format specifiers |
| Can handle all data types | Handle only `char` and strings |
| Output can be controlled by width, precision | No control over appearance |
| `scanf()`, `printf()`, `fscanf()`, `fprintf()` | `getchar()`, `putchar()`, `gets()`, `puts()`, `getch()` |
| Slower, more flexible | Faster, simpler |

#### Syntax
- `printf("format string", variable_list);`
- `scanf("format string", &variable_list);`
- `ch = getchar();`, `putchar(ch);`, `puts("string");`

#### Example
```c
#include <stdio.h>
int main(void)
{
    int age;
    char ch;
    printf("Enter age: ");
    scanf("%d", &age);              /* formatted input */
    printf("Age = %d\n", age);      /* formatted output */
    getchar();                      /* consume newline */
    printf("Enter a character: ");
    ch = getchar();                 /* unformatted input */
    printf("You typed: ");
    putchar(ch);                    /* unformatted output */
    putchar('\n');
    puts("Done");                   /* unformatted output of a string */
    return 0;
}
```
Output (with input 25 and Z):
```text
Enter age: Age = 25
Enter a character: You typed: Z
Done
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which pair is formatted I/O?
   A. getchar() and putchar()
   B. printf() and scanf()
   C. gets() and puts()
   D. getch() and putchar()
   Answer: B. printf and scanf use format specifiers. (Key point: Formatted)

2. Which statement is true?
   A. Unformatted functions handle all data types
   B. Formatted functions handle all data types, unformatted only char and strings
   C. Both handle only char
   D. Formatted handle only int
   Answer: B. Format specifiers let formatted functions handle every type. (Key point: Data types)

3. Which gives control over width and precision?
   A. putchar()
   B. puts()
   C. printf()
   D. getchar()
   Answer: C. Formatted output supports width and precision. (Key point: Control of output)

4. Compared with formatted I/O, unformatted I/O is:
   A. Slower and more flexible
   B. Faster and simpler
   C. Same speed
   D. Unable to read characters
   Answer: B. Unformatted functions are faster and simpler but with less control. (Key point: Speed)

## Related in Computer Programming

- [Formatted and unformatted I/O in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-unformatted-io) — Computer Programming, chapter 11
- [Formatted I/O in FORTRAN with syntax](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-io-syntax) — Computer Programming, chapter 11
- [Pattern: PULCHOWK using unformatted output](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apattern-pulchowk) — Computer Programming, chapter 4
- [Pattern N, eee, PPPPP using unformatted I/O](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apattern-n-e-p-a-l) — Computer Programming, chapter 4
- [I/O functions used with data files](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-io-functions) — Computer Programming, chapter 10, asked 2×

## Related in other subjects

- [ios class functions and flags for formatted I/O](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aios-flags-formatted-io) — Object Oriented Programming, chapter 8, asked 2×
- [CE amplifier input, output resistance and gain (RE1, RE2)](https://www.bctengineer.com/question.md?key=semester_3%2Felectronics_devices_and_circuit%3Ace-partial-bypass-numeric) — Electronics Devices and Circuit, chapter 2
- [Bridge with diode, α-dependent output and input current](https://www.bctengineer.com/question.md?key=semester_7%2Fpower_electronics%3Abridge-d1-highly-inductive-fundamental) — Power Electronics, chapter 2
- [Output of e^(−2t)u(t) to a rectangular input](https://www.bctengineer.com/question.md?key=semester_4%2Fsignals_and_systems%3Aconvolution-exponential-rect-input) — Signals and Systems, chapter 5, asked 4×
