Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

303 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 71–80 of 303
Topics in C Programming
Q.71 Easy File Handling
What will fseek(fp, 0, SEEK_END) do?
A Moves pointer to beginning of file
B Moves pointer to end of file
C Moves pointer 0 bytes forward
D Closes the file
Correct Answer:  B. Moves pointer to end of file
EXPLANATION

SEEK_END moves pointer relative to end of file. Offset 0 means go to the exact end. SEEK_SET (beginning) and SEEK_CUR (current) are other origin options.

Take Test
Q.72 Easy File Handling
Which function writes formatted output to a file?
A fscanf()
B fprintf()
C fwrite()
D fputs()
Correct Answer:  B. fprintf()
EXPLANATION

fprintf() writes formatted data to file (like printf() but to file). fscanf() reads formatted data. fwrite() writes binary data. fputs() writes strings.

Take Test
Q.73 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.

Take Test
Q.74 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.

Take Test
Q.75 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.

Take Test
Q.76 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.

Take Test
Q.77 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.

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

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

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