---
title: "Text file versus binary file"
subject: "Computer Programming"
chapter: 10
key: "semester_1/computer_programming:text-vs-binary-file"
source: https://www.bctengineer.com/q/semester_1/computer_programming/text-vs-binary-file
site: BCT Engineering
---

# Text file versus binary file

Computer Programming · Chapter 10: Data Files

- Asked in: 2069 Chaitra, 2 marks
- Video: [Text Files Vs Binary Files | File Handling | Text file | Binary file | Data structures](https://www.youtube.com/watch?v=v7IpCq5YL68) — Dr. Mukund Kulkarni
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/text-vs-binary-file
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-10

## Question

Differentiate between text file and binary file.

## Short answer

Text files store data as readable ASCII characters; they are larger, use functions like fprintf/fscanf, and open with modes "r" or "w". Binary files store data as raw bytes in memory representation; they are smaller, use fread/fwrite, and modes "rb" or "wb".

## Answer

| Basis | Text file | Binary file |
|---|---|---|
| Storage | Data as readable characters (ASCII) | Data in the same form as in memory (raw bytes) |
| Readable | Can be opened in an editor | Not readable in an editor |
| Size | Larger (a number like 12345 uses 5 bytes) | Smaller (an `int` always uses 4 bytes) |
| Functions | `fprintf`, `fscanf`, `fgets`, `fputs` | `fwrite`, `fread` |
| Newline | Translated on some systems (e.g. Windows) | No translation |
| Speed | Slower (conversion needed) | Faster (no conversion) |
| Mode | `"r"`, `"w"` | `"rb"`, `"wb"` |

## Check yourself

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

1. How is data stored in a text file compared with a binary file?
   A. Text: readable characters; binary: same form as in memory
   B. Both are readable
   C. Text: raw bytes; binary: ASCII
   D. No difference
   Answer: A. Text files store characters, binary files store raw bytes. (Key point: Storage form)

2. How many bytes does 12345 take in a text file versus an int in a binary file?
   A. 5 and 4
   B. 4 and 5
   C. 5 and 5
   D. 2 and 4
   Answer: A. Text uses one byte per digit (5), a binary int is always 4 bytes. (Key point: Size of 12345)

3. Which functions go with binary files?
   A. fprintf and fscanf
   B. fwrite and fread
   C. fgets and fputs
   D. printf and scanf
   Answer: B. Block functions fwrite and fread are used with binary files. (Key point: Functions)

## Related in Computer Programming

- [Employee text file; sort into binary file](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-employee-sorted-binary) — Computer Programming, chapter 10
- [Binary file of 48 students; highest mark](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-binary-48-students-highest) — Computer Programming, chapter 10

## Related in other subjects

- [File stream; student binary file program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-stream-student-binary) — Object Oriented Programming, chapter 8
- [Audio quality versus file size](https://www.bctengineer.com/question.md?key=semester_8%2Fmultimedia_system%3Aquality-vs-file-size) — Multimedia System, chapter 2
