5.4.1 - Overview of File Handling.
1. Which function is used to open a file in C?
Correct Answer: (A) fopen()
2. What is the return type of fopen() function?
Correct Answer: (B) FILE*
3. Which mode in fopen() is used to open a file for writing at the end of the file?
Correct Answer: (C) "a"
4. Which function is used to read a single character from a file?
Correct Answer: (A) getc()
5. What does the fclose() function do in C?
Correct Answer: (B) Close a file
6. What is the correct syntax for closing a file in C?
Correct Answer: (A) fclose(file);
7. What is the function used to get the current position of the file pointer?
Correct Answer: (B) ftell()
8. Which function is used to write formatted data into a file?
Correct Answer: (A) fprintf()
9. What happens if a file opened in "r" mode does not exist?
Correct Answer: (B) fopen() returns NULL
10. Which function is used to set the position of the file pointer in C?
Correct Answer: (B) fseek()
11. How do you write an integer into a file?
Correct Answer: (B) putw()
12. Which function is used to read a string from a file in C?
Correct Answer: (C) fgets()
13. What is the file pointer variable type in C?
Correct Answer: (A) FILE*
14. What does the rewind() function do in file handling?
Correct Answer: (C) Moves the file pointer to the beginning of the file
15. What is the default mode when a file is opened using fopen()?
Correct Answer: (A) "r"
16. What is the purpose of the ftell() function in C?
Correct Answer: (B) To get the current file position
17. Which function is used to write a character to a file?
Correct Answer: (C) fputc()
18. How do you read an integer from a file?
Correct Answer: (C) getw()
19. What does the function fseek() do in file handling?
Correct Answer: (C) Sets the file pointer to a specific location
20. What is the result of opening a file in "w" mode if the file already exists?
Correct Answer: (B) The file is truncated