fclose() terminates the file stream, flushes any buffered data to disk, and releases the file handle. It doesn't delete or clear the file.
Q.222Easy
Which function writes formatted output to a file?
Answer: B
fprintf() writes formatted data to file (like printf() but to file). fscanf() reads formatted data. fwrite() writes binary data. fputs() writes strings.
Q.223Easy
What will fseek(fp, 0, SEEK_END) do?
Answer: B
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.
Q.224Easy
Which function reads formatted data from a file?
Answer: B
fscanf() reads formatted data from file (like scanf() but from file). fgets() reads strings. fread() reads binary data. getc() reads single character.
Q.225Easy
What is returned by fopen() if file opening fails?
Answer: B
fopen() returns NULL pointer on failure. Proper practice is to check: if(fp == NULL) {...error handling...}. Returning -1 is for system calls like open().
Advertisement
Q.226Easy
What does the third parameter of fseek() represent?
Answer: B
Third parameter is 'whence': SEEK_SET (beginning), SEEK_CUR (current position), SEEK_END (end). Second parameter specifies offset in bytes.
Q.227Easy
Which header file must be included to use file handling functions in C?
Answer: A
stdio.h (Standard Input/Output) contains all file handling functions like fopen(), fclose(), fread(), fwrite(), etc.
Q.228Easy
What does the 'w+' mode do when opening a file with fopen()?
Answer: A
'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.
Q.229Easy
Which function is used to write a single character to a file?
Answer: A
fputc() writes a single character to the specified file. fgetc() reads a character, fwrite() writes blocks, and fprintf() writes formatted output.
Q.230Easy
What is the return value of feof(fp) when the end of file is reached?
Answer: A
feof(fp) returns a non-zero value when EOF (End Of File) is reached, and returns zero when not at EOF.
Q.231Easy
In C file handling, what does rewind(fp) do?
Answer: A
rewind(fp) repositions the file pointer to the start of the file. It's equivalent to fseek(fp, 0, SEEK_SET).
Q.232Easy
Which file opening mode allows both reading and writing without truncating existing content?
Answer: A
Mode 'r+' opens file for reading and writing without truncating. 'w+' truncates the file, 'a+' appends, and 'x+' is for exclusive creation.
Q.233Easy
What does fseek(fp, 0, SEEK_END) accomplish?
Answer: B
SEEK_END moves the file pointer to the end of file. SEEK_SET goes to beginning, SEEK_CUR to current position.
Q.234Easy
Which function returns the current position of file pointer?
Answer: B
ftell() returns the current file position as a long integer. fgetpos() stores position in a fpos_t structure. rewind() resets to beginning.
Q.235Easy
Which mode opens file in text format with write permission only?
Answer: B
'w' mode opens file in text format for writing. 'wb' is binary write. 'wt' is explicitly text write but 'w' is default text mode.
Q.236Easy
Which function is used to check if the end-of-file (EOF) has been reached in C file handling?
Answer: A
feof() is the standard C library function that returns non-zero if EOF has been reached on the given file stream. Other options are not valid C functions.
Q.237Easy
In a file processing application, what is the primary difference between 'wb' and 'w' file modes?
Answer: A
'w' opens file in text mode (converts line endings), while 'wb' opens in binary mode (no conversion). This matters when handling platform-specific line endings (\r\n vs \n).
Q.238Easy
Which header file is required for dynamic memory allocation functions?
Answer: B
The <stdlib.h> header file contains declarations for malloc(), calloc(), realloc(), and free() functions.
Q.239Easy
What does calloc() do differently from malloc()?
Answer: B
calloc() takes two arguments (number of elements and size) and initializes all allocated bytes to zero, unlike malloc().
Q.240Easy
Which function is used to free dynamically allocated memory?
Answer: C
free() is the standard function to deallocate memory previously allocated by malloc(), calloc(), or realloc().