Home Subjects C Programming File Handling

C Programming
File Handling

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 41–50 of 100
Topics in C Programming
Q.41 Medium File Handling
Which mode allows both reading and appending without truncating existing content?
A a+
B w+
C r+
D ab+
Correct Answer:  A. a+
EXPLANATION

'a+' mode opens file for reading and appending. New data is added at the end without removing existing content. 'w+' would truncate the file.

Take Test
Q.42 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.43 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.44 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.45 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
Q.46 Easy File Handling
Which header file must be included to use file handling functions in C?
A #include
B #include
C #include
D #include
Correct Answer:  A. #include
EXPLANATION

stdio.h (Standard Input/Output) contains all file handling functions like fopen(), fclose(), fread(), fwrite(), etc.

Take Test
Q.47 Hard File Handling
A large binary file of 10GB is being processed. Reading entire file into memory is impossible. Which approach is best?
A Use fread() to read file in chunks, process each chunk
B Use multiple fopen() calls on same file
C Split file manually into smaller files
D Use fscanf() which has built-in chunking
Correct Answer:  A. Use fread() to read file in chunks, process each chunk
EXPLANATION

fread(buffer, size, count, fp) efficiently reads file in manageable chunks. Process each chunk, then read next. This is standard practice for large file handling.

Take Test
Q.48 Easy File Handling
What does the third parameter of fseek() represent?
A Number of bytes to move
B The reference point (origin) for seeking
C File handle identifier
D Direction (forward or backward)
Correct Answer:  B. The reference point (origin) for seeking
EXPLANATION

Third parameter is 'whence': SEEK_SET (beginning), SEEK_CUR (current position), SEEK_END (end). Second parameter specifies offset in bytes.

Take Test
Q.49 Hard File Handling
A program uses fgetc() to read 100,000 characters from a file sequentially. Which alternative would be more efficient?
A Use fgets() with larger buffer
B Use fread() with appropriate buffer size
C Use fscanf() with %c format
D Continue with fgetc(); efficiency doesn't matter
Correct Answer:  B. Use fread() with appropriate buffer size
EXPLANATION

fread() with buffer reads multiple bytes per call, reducing function call overhead. fgetc() makes 100,000 separate calls. fgets() is limited to reading up to newline.

Take Test
Q.50 Medium File Handling
In a file opened in "a+" mode, where does the file pointer initially point?
A Beginning of file
B End of file
C Middle of file
D Undefined location
Correct Answer:  B. End of file
EXPLANATION

In append mode "a" or "a+", file pointer initially points to end of file for writing. For reading in "a+", you must explicitly seek to read from start.

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