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 61–70 of 303
Topics in C Programming
Q.61 Easy File Handling
What does fseek(fp, 0, SEEK_END) accomplish?
A Moves pointer to beginning of file
B Moves pointer to end of file
C Moves pointer to current position
D Closes the file pointer
Correct Answer:  B. Moves pointer to end of file
EXPLANATION

SEEK_END moves the file pointer to the end of file. SEEK_SET goes to beginning, SEEK_CUR to current position.

Take Test
Q.62 Easy File Handling
Which file opening mode allows both reading and writing without truncating existing content?
A r+
B w+
C a+
D x+
Correct Answer:  A. r+
EXPLANATION

Mode 'r+' opens file for reading and writing without truncating. 'w+' truncates the file, 'a+' appends, and 'x+' is for exclusive creation.

Take Test
Q.63 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.64 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.65 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.66 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.67 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.68 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.69 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().

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

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