C Programming — File Handling
C language from basics to advanced placement prep
27 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 27 questions in File Handling
Q.1 Easy File Handling
In a file processing application, what is the primary difference between 'wb' and 'w' file modes?
A 'wb' opens in binary mode while 'w' opens in text mode
B 'w' is faster than 'wb'
C 'wb' allows reading while 'w' does not
D There is no difference in modern C compilers
Correct Answer:  A. 'wb' opens in binary mode while 'w' opens in text mode
EXPLANATION

'w' opens file in text mode (converts line endings), while 'wb' opens in binary mode (no conversion). This matters when handling platform-specific line endings (\r\n vs \n).

Take Test
Q.2 Easy File Handling
Which function is used to check if the end-of-file (EOF) has been reached in C file handling?
A feof(fp)
B eof(fp)
C iseof(fp)
D checkeof(fp)
Correct Answer:  A. feof(fp)
EXPLANATION

feof() is the standard C library function that returns non-zero if EOF has been reached on the given file stream. Other options are not valid C functions.

Take Test
Q.3 Easy File Handling
Which mode opens file in text format with write permission only?
A wb
B w
C wt
D wa
Correct Answer:  B. w
EXPLANATION

'w' mode opens file in text format for writing. 'wb' is binary write. 'wt' is explicitly text write but 'w' is default text mode.

Take Test
Q.4 Easy File Handling
Which function returns the current position of file pointer?
A fgetpos()
B ftell()
C fseek()
D rewind()
Correct Answer:  B. ftell()
EXPLANATION

ftell() returns the current file position as a long integer. fgetpos() stores position in a fpos_t structure. rewind() resets to beginning.

Take Test
Q.5 Easy File Handling
What does fseek(fp, 0, SEEK_END) accomplish?
A Moves pointer to beginning of file
B Moves pointer to end of file
C Moves pointer to current position
D Closes the file pointer
Correct Answer:  B. Moves pointer to end of file
EXPLANATION

SEEK_END moves the file pointer to the end of file. SEEK_SET goes to beginning, SEEK_CUR to current position.

Take Test
Advertisement
Q.6 Easy File Handling
Which file opening mode allows both reading and writing without truncating existing content?
A r+
B w+
C a+
D x+
Correct Answer:  A. r+
EXPLANATION

Mode 'r+' opens file for reading and writing without truncating. 'w+' truncates the file, 'a+' appends, and 'x+' is for exclusive creation.

Take Test
Q.7 Easy File Handling
In C file handling, what does rewind(fp) do?
A Moves the file pointer to the beginning of the file
B Closes and reopens the file
C Moves the file pointer to the end of the file
D Flushes the file buffer
Correct Answer:  A. Moves the file pointer to the beginning of the file
EXPLANATION

rewind(fp) repositions the file pointer to the start of the file. It's equivalent to fseek(fp, 0, SEEK_SET).

Take Test
Q.8 Easy File Handling
What is the return value of feof(fp) when the end of file is reached?
A Non-zero value (true)
B Zero (false)
C -1
D NULL pointer
Correct Answer:  A. Non-zero value (true)
EXPLANATION

feof(fp) returns a non-zero value when EOF (End Of File) is reached, and returns zero when not at EOF.

Take Test
Q.9 Easy File Handling
Which function is used to write a single character to a file?
A fputc()
B fgetc()
C fwrite()
D fprintf()
Correct Answer:  A. fputc()
EXPLANATION

fputc() writes a single character to the specified file. fgetc() reads a character, fwrite() writes blocks, and fprintf() writes formatted output.

Take Test
Q.10 Easy File Handling
What does the 'w+' mode do when opening a file with fopen()?
A Opens file for reading and writing, creates if doesn't exist
B Opens file for writing only, appends data at end
C Opens file for reading only
D Opens file in binary write mode
Correct Answer:  A. Opens file for reading and writing, creates if doesn't exist
EXPLANATION

'w+' mode opens a file for both reading and writing. If the file doesn't exist, it creates a new one. If it exists, it truncates the file to zero length.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips