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 61–70 of 291
Topics in C Programming
Q.61 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).

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

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

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

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

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

Test
Q.67 Easy File Handling
What is returned by fopen() if file opening fails?
A Returns -1
B Returns NULL pointer
C Returns empty string
D Throws an exception
Correct Answer:  B. Returns NULL pointer
EXPLANATION

fopen() returns NULL pointer on failure. Proper practice is to check: if(fp == NULL) {...error handling...}. Returning -1 is for system calls like open().

Test
Q.68 Easy File Handling
Which function reads formatted data from a file?
A fgets()
B fscanf()
C fread()
D getc()
Correct Answer:  B. fscanf()
EXPLANATION

fscanf() reads formatted data from file (like scanf() but from file). fgets() reads strings. fread() reads binary data. getc() reads single character.

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

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

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