Recall & Review
beginner
What does the file mode "r" mean in C?
The mode "r" opens a file for reading. The file must exist, or fopen() will return NULL.
Click to reveal answer
beginner
What happens if you open a file with mode "w" in C?
The mode "w" opens a file for writing. If the file exists, it is truncated (emptied). If it doesn't exist, a new file is created.
Click to reveal answer
intermediate
Explain the difference between "a" and "w" file modes.
"a" opens a file for appending. Data is added to the end without deleting existing content. "w" opens for writing and clears the file first.
Click to reveal answer
intermediate
What does the mode "r+" allow you to do?
"r+" opens a file for both reading and writing. The file must exist. You can read and write anywhere in the file.
Click to reveal answer
intermediate
What is the difference between "b" and text modes in file opening?
The "b" mode opens a file in binary mode, meaning data is read/written exactly as is. Without "b", the file is opened in text mode, which may translate line endings.
Click to reveal answer
Which file mode opens a file for reading and writing but requires the file to exist?
✗ Incorrect
The "r+" mode opens a file for both reading and writing but the file must already exist.
What happens if you open a file with mode "w" and the file already exists?
✗ Incorrect
Opening with "w" clears the file content before writing.
Which mode should you use to add data to the end of a file without deleting existing content?
✗ Incorrect
"a" mode appends data to the end of the file.
What does the "b" in file modes like "rb" or "wb" stand for?
✗ Incorrect
"b" means binary mode, which reads/writes data exactly without translation.
If you try to open a non-existent file with mode "r", what happens?
✗ Incorrect
Mode "r" requires the file to exist; otherwise fopen() returns NULL.
Describe the main differences between the file modes "r", "w", and "a" in C.
Think about what happens to the file content and if the file must exist.
You got /4 concepts.
Explain why and when you would use binary mode ("b") when opening files in C.
Consider files that are not plain text.
You got /3 concepts.