0
0
Cprogramming~5 mins

Opening and closing files - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Afileopen()
Bfopen()
Copenfile()
Dopen()
What mode should you use with fopen() to write to a file?
A"w"
B"rw"
C"a"
D"r"
What does fclose() do?
AReads data from a file
BDeletes a file
CWrites data to a file
DCloses an open file
If fopen() fails to open a file, what does it return?
A-1
B0
CNULL
Dfalse
Why should you always close files after opening them?
ATo free memory and save data
BTo speed up the program
CTo delete the file
DTo rename the file
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.