0
0
Cprogramming~5 mins

File modes in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A"r+"
B"w"
C"a"
D"r"
What happens if you open a file with mode "w" and the file already exists?
AThe file is opened for reading only
BThe file is appended to
CThe file is truncated (emptied)
DThe file is left unchanged
Which mode should you use to add data to the end of a file without deleting existing content?
A"w"
B"a"
C"r"
D"r+"
What does the "b" in file modes like "rb" or "wb" stand for?
ABinary mode
BBuffered mode
CBasic mode
DBlock mode
If you try to open a non-existent file with mode "r", what happens?
AThe file is created
BThe file is opened for writing
CThe file is truncated
Dfopen() 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.