Govt Exams
Without fclose() or fflush(), buffered data remains in memory. If program terminates, that data never reaches disk. System may flush on exit but it's unreliable.
In text mode, fseek() behavior is implementation-dependent due to line-ending conversions (\r\n vs \n). Binary mode provides more predictable fseek() behavior with absolute byte positions.
fgets(buffer, size, fp) reads at most size-1 characters or until newline, whichever comes first, then adds null terminator. Remaining characters stay in stream for next read.
fgets() reads up to and including the newline character. For an empty line, it reads just the newline character into the buffer.
fscanf() reads formatted data from a file stream, functioning as the file equivalent of scanf().
In text mode, platform-specific line endings (\r\n on Windows, \n on Unix) are translated. Binary mode reads bytes as-is without translation.
fseek(fp, 0, SEEK_END) positions the file pointer at the end of file. SEEK_END is the third constant in <stdio.h>.
ftell() returns the current position of the file pointer as a long integer offset from the beginning of the file.
fopen() returns NULL pointer on failure. Checking 'fp == NULL' or '!fp' is the correct approach. Option C uses explicit NULL check which is clearer.
clearerr() clears both the EOF indicator and the error flag associated with a stream.