Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

291 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 291
Topics in C Programming
Q.71 Easy File Handling
What does the fclose() function do?
A Clears the file content
B Closes the file and flushes the buffer
C Moves file pointer to end
D Deletes the file from disk
Correct Answer:  B. Closes the file and flushes the buffer
EXPLANATION

fclose() terminates the file stream, flushes any buffered data to disk, and releases the file handle. It doesn't delete or clear the file.

Test
Q.72 Easy File Handling
Which mode allows both reading and writing to a file, creating it if it doesn't exist?
A "r+"
B "w+"
C "a+"
D "rw"
Correct Answer:  B. "w+"
EXPLANATION

"w+" opens file for reading and writing, truncating it if it exists, and creating it if it doesn't. "r+" requires file to exist. "a+" opens in append mode with read capability.

Test
Q.73 Easy File Handling
What is the correct syntax to open a file named 'data.txt' in read mode?
A fopen('data.txt', 'r')
B fopen("data.txt", "r")
C open("data.txt", READ)
D file_open("data.txt", 'r')
Correct Answer:  B. fopen("data.txt", "r")
EXPLANATION

fopen() uses double quotes for string arguments in C. The first argument is filename and second is mode. Single quotes are for characters, not strings.

Test
Q.74 Easy File Handling
Which function is used to determine the current position in a file?
A ftell()
B fseek()
C rewind()
D fgetpos()
Correct Answer:  A. ftell()
EXPLANATION

ftell() returns the current position (as a long integer) of the file pointer in the file. fseek() is used to change position, rewind() resets to beginning, and fgetpos() stores position in a structure.

Test
Q.75 Easy File Handling
In file handling, what does the 'b' flag in file modes like 'rb' or 'wb' indicate?
A Binary mode operation
B Buffered mode operation
C Bidirectional mode operation
D Backup mode operation
Correct Answer:  A. Binary mode operation
EXPLANATION

The 'b' flag specifies binary mode, which prevents any translation of line endings or special characters.

Test
Q.76 Easy File Handling
Which of the following file modes in fopen() allows reading only?
A "w"
B "r"
C "a"
D "w+"
Correct Answer:  B. "r"
EXPLANATION

The 'r' mode opens a file for reading only. The file must exist, otherwise fopen() returns NULL.

Test
Q.77 Easy File Handling
When opening a file in 'w' mode, what happens if the file already exists?
A The file is truncated and all previous content is deleted
B The file is opened in append mode automatically
C An error is returned and file is not opened
D The file pointer is positioned at the end
Correct Answer:  A. The file is truncated and all previous content is deleted
EXPLANATION

Opening a file in 'w' mode truncates the file to zero length if it exists, discarding all previous content.

Test
Q.78 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.

Test
Q.79 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.

Test
Q.80 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.

Test
IGET
IGET AI
Online · Exam prep assistant
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