Recall & Review
beginner
What function is used to open a file in C?
The
fopen() function is used to open a file in C. It requires the file name and mode (like "r" for read, "w" for write).Click to reveal answer
beginner
What does the mode "r" mean when opening a file with
fopen()?The mode "r" means open the file for reading only. The file must exist, or
fopen() will return NULL.Click to reveal answer
beginner
How do you properly close a file in C?
Use the
fclose() function and pass the file pointer returned by fopen(). This frees resources and saves changes.Click to reveal answer
intermediate
What happens if you forget to close a file after opening it?
If you forget to close a file, it can cause memory leaks or data not being saved properly. Always close files to keep your program safe.
Click to reveal answer
beginner
What does
fopen() return if it fails to open a file?fopen() returns NULL if it cannot open the file (for example, if the file does not exist in read mode). Always check for NULL before using the file pointer.Click to reveal answer
Which function opens a file in C?
✗ Incorrect
The correct function to open a file in C is
fopen().What mode should you use with
fopen() to write to a file?✗ Incorrect
Use mode "w" to open a file for writing. It creates the file if it doesn't exist or truncates it if it does.
What does
fclose() do?✗ Incorrect
fclose() closes an open file and releases resources.If
fopen() fails to open a file, what does it return?✗ Incorrect
fopen() returns NULL if it cannot open the file.Why should you always close files after opening them?
✗ Incorrect
Closing files frees memory and ensures data is saved properly.
Explain how to open a file for reading and then close it in C.
Think about the steps: open, check, use, close.
You got /4 concepts.
What are the risks of not closing a file after opening it?
Consider what happens inside the computer when files stay open.
You got /3 concepts.