Which of the following are correct file opening modes in C?
a) “r”, “w”, “b”
b) “r”, “w”, “rb”, “wb”
c) “rb”, “w”, “wb”, “r”
d) “rw”, “wr”, “r”, “w”
Answer:
b) “r”, “w”, “rb”, “wb”
Explanation:
In C, file opening modes are specified when you open a file using the fopen()
function. Common modes include "r"
for reading, "w"
for writing, "rb"
for reading in binary mode, and "wb"
for writing in binary mode. These modes tell the program how to interact with the file—whether to read from it, write to it, or handle it as a binary file.
Understanding file opening modes is essential for performing file operations correctly and avoiding errors when working with files in C.