Question:easy

What will happen if you do not call fclose(fp), after opening a file in C?

Show Hint

fclose flushes buffers and frees resources; skipping it risks losing both.
Updated On: Jul 2, 2026
  • It may cause a memory leak or data loss.
  • The file remains in memory even after the program exits.
  • The file will be closed automatically without any issues.
  • The program will not compile.
Show Solution

The Correct Option is A

Solution and Explanation

Every $fopen$ hands you resources: a buffer, a FILE object, and an OS-level file descriptor. The matching $fclose$ is the cleanup step that empties the buffer to disk and returns those resources.

Skip $fclose$ and two bad things can follow. First, whatever sits in the write buffer may never reach the file, so you lose data. Second, the held resources are not released while the program runs, which leaks memory and descriptors.

The file does not linger in memory after exit, and nothing stops the program from compiling, so those choices are wrong.

\[\boxed{\text{May cause a memory leak or data loss (A)}}\]
Was this answer helpful?
0