C Programming — File Handling
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in File Handling
Q.91 Medium File Handling
What is the difference between fgetc() and getc()?
A fgetc() is a function while getc() is a macro
B getc() is faster than fgetc()
C fgetc() can only read one character
D getc() requires file pointer argument
Correct Answer:  A. fgetc() is a function while getc() is a macro
EXPLANATION

fgetc() is a function that reads a character from a file, while getc() is a macro. Both serve the same purpose but getc() may be faster due to macro expansion.

Take Test
Q.92 Medium File Handling
What does feof() function check?
A Whether end of file is reached
B Whether file is empty
C Whether file exists
D Whether file is open
Correct Answer:  A. Whether end of file is reached
EXPLANATION

feof() returns true (non-zero) if the end-of-file indicator is set for the given file stream, otherwise it returns 0.

Take Test
Q.93 Medium File Handling
Which function sets the file position to a specific location?
A fseek()
B setpos()
C fsetpos()
D seek()
Correct Answer:  A. fseek()
EXPLANATION

fseek() is used to move the file pointer to a specific position in the file. It takes three arguments: file pointer, offset, and origin.

Take Test
Q.94 Medium File Handling
What is the purpose of ftell() function?
A Returns current file position
B Tells if file exists
C Tells file name
D Tells file size
Correct Answer:  A. Returns current file position
EXPLANATION

ftell() returns the current position of the file pointer in bytes from the beginning of the file.

Take Test
Q.95 Medium File Handling
Which function writes formatted data to a file?
A fprintf()
B fwrite()
C fputs()
D fputc()
Correct Answer:  A. fprintf()
EXPLANATION

fprintf() writes formatted data to a file, similar to printf() but with a file pointer as the first argument.

Take Test
Advertisement
Q.96 Medium File Handling
What does fgets() function do?
A Reads a line from a file
B Gets file status
C Gets file size
D Gets file pointer position
Correct Answer:  A. Reads a line from a file
EXPLANATION

fgets() reads a string from a file until a newline character or end of file is encountered. It takes three arguments: buffer, size, and file pointer.

Take Test
Q.97 Easy File Handling
Which mode opens a file for writing and truncates it if it exists?
A "w"
B "a"
C "r+"
D "w+"
Correct Answer:  A. "w"
EXPLANATION

"w" mode opens a file for writing. If the file exists, it truncates the file to zero length. If it doesn't exist, a new file is created.

Take Test
Q.98 Easy File Handling
Which function is used to close a file in C?
A fclose()
B close_file()
C file_close()
D closefile()
Correct Answer:  A. fclose()
EXPLANATION

fclose() is the standard function to close an opened file stream. It returns 0 on success and EOF on error.

Take Test
Q.99 Easy File Handling
What does the mode 'rb' mean in fopen()?
A Read in binary mode
B Read and backup mode
C Rewrite and binary mode
D Remove and backup mode
Correct Answer:  A. Read in binary mode
EXPLANATION

'rb' mode opens a file for reading in binary format. Binary mode reads the exact bytes without any text conversion.

Take Test
Q.100 Easy File Handling
Which function is used to open a file in C?
A fopen()
B open_file()
C file_open()
D openfile()
Correct Answer:  A. fopen()
EXPLANATION

fopen() is the standard C library function used to open a file. It takes two arguments: filename and mode.

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