Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Understand what fopen does. It allocates a FILE structure and often an internal buffer, and it associates them with an open operating system file handle.

Step 2: Understand what fclose does. It flushes any buffered data to disk, releases the buffer and FILE structure, and frees the file handle.

Step 3: If you never call fclose, the buffered data may not be flushed, so recently written data can be lost. The allocated resources also stay held, which is a resource or memory leak.

Step 4: Check the other options. The file does not stay in memory after the program exits, the operating system reclaims handles at exit but that is not guaranteed to flush your buffer, and the code still compiles fine.

Step 5: The correct effect is a possible memory leak or data loss. The answer is option A.
Was this answer helpful?
0
0