This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 24 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 24 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. What is the first step in writing to a file? A) Deleting the file. B) Closing the file. C) Reading the file. D) Opening the file. Show Answer Correct Answer: D) Opening the file. 2. What is the purpose of the 'fgetc()' function in C? A) To read the next character from a file stream. B) To check if a file exists. C) To write a character to a file. D) To close a file. Show Answer Correct Answer: A) To read the next character from a file stream. 3. Explain the process of writing data to a binary file. A) The process involves opening the binary file, converting data to binary format, writing the binary data, and then closing the file. B) Skipping the step of closing the file after writing. C) Writing the data in reverse order. D) Converting data to text format before writing. Show Answer Correct Answer: A) The process involves opening the binary file, converting data to binary format, writing the binary data, and then closing the file. 4. Which statement is TRUE about the 'EOF' function? A) It writes data to the file. B) It returns FALSE when the file is first opened. C) It reads the last line of the file. D) It returns TRUE if the end of the file is reached. Show Answer Correct Answer: D) It returns TRUE if the end of the file is reached. 5. A programmer want to read, write or append file to do some specific operation .while doing this, a programmer must ..... file. A) Create. B) Close. C) Create. D) Open. Show Answer Correct Answer: D) Open. 6. Which of the following is an example of pseudocode for reading a line from a file? A) 'READ line FROM file.txt'. B) 'line = readFile("file.txt")'. C) 'line = file.readLine()'. D) 'OPEN file.txt FOR READ'. Show Answer Correct Answer: A) 'READ line FROM file.txt'. 7. Which Python module is commonly used for handling CSV files? A) Json. B) Xml. C) Txt. D) Csv. Show Answer Correct Answer: D) Csv. 8. Matilda and Alexander are working on a coding project. Can you help them figure out the correct way to close a file object named file? A) Close(file). B) File.close. C) File.close(). D) Close.file(). Show Answer Correct Answer: C) File.close(). 9. Apa nama method yang membaca semua baris dalam file dan menyimpannya dalam list? A) .read(). B) .readline(). C) .readall(). D) .readlines(). Show Answer Correct Answer: D) .readlines(). 10. What is the purpose of using Fileinputstream in Java? A) To read data from a file. B) To create a new file. C) To write data to a file. D) To delete a file. Show Answer Correct Answer: A) To read data from a file. 11. What is the use of seek() method in files? A) Sets the file's current position at the offset. B) Sets the file's previous position at the offset. C) Sets the file's current position within the file. D) None of the mentioned. Show Answer Correct Answer: C) Sets the file's current position within the file. 12. What does the 'close()' method do for a file object? A) Opens the file. B) Reads the file. C) Closes the file and saves changes. D) Deletes the file. Show Answer Correct Answer: C) Closes the file and saves changes. 13. "w" mode deletes everything first, and then writes the content. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 14. What could happen if you forget to close a file after writing to it? A) The file will be deleted. B) You may not be able to access the file again. C) The file will be read-only. D) The file will be encrypted. Show Answer Correct Answer: B) You may not be able to access the file again. 15. Select a function which is used as a formatted output file function A) Fputs(). B) Printf(). C) Fprintf(). D) Puts(). Show Answer Correct Answer: C) Fprintf(). 16. How do you check if a file exists in Python? A) Os.path.getsize(). B) Os.path.isfile(). C) Os.path.isdir(). D) Os.path.exists(). Show Answer Correct Answer: D) Os.path.exists(). 17. Which read method(s) will read the entire contents of the file (by default)? A) File.read(). B) File.readline(). C) File.readlines(). D) File.reads(). Show Answer Correct Answer: A) File.read(). 18. What does the suffix attribute of a Path object return? A) The extension of the file. B) The name of the file. C) All the above. D) None of the above. Show Answer Correct Answer: A) The extension of the file. 19. What is the difference between 'read()' and 'readlines()'? A) 'read()' returns a byte object; 'readlines()' returns a dictionary of strings. B) 'read()' returns a single string; 'readlines()' returns a list of strings. C) 'read()' returns a list of strings; 'readlines()' returns a single string. D) 'read()' reads the file line by line; 'readlines()' reads the entire file at once. Show Answer Correct Answer: B) 'read()' returns a single string; 'readlines()' returns a list of strings. 20. Name the module that has to be imported to write a csv file. A) Csv module. B) CSV module. C) Pickle module. D) Csv module. Show Answer Correct Answer: B) CSV module. 21. In which mode does a file get created if it doesn't already exist? A) WRITE mode. B) READ mode. C) EXECUTE mode. D) APPEND mode. Show Answer Correct Answer: A) WRITE mode. 22. Why is data stored in a file instead of only using variables in a program? A) To allow data to persist after the program stops running. B) To improve the speed of program execution. C) To reduce memory usage while the program runs. D) To prevent the need for user input. Show Answer Correct Answer: A) To allow data to persist after the program stops running. 23. A(n) ..... access file is also known as a direct access file. A) Sequential. B) Random. C) Numbered. D) Text. Show Answer Correct Answer: B) Random. 24. Which exception is raised when trying to open a file that does not exist? A) FileNotFoundError. B) FileNotAvailableError. C) FileAccessError. D) FileMissingException. Show Answer Correct Answer: A) FileNotFoundError. 25. What is the purpose of the 'newline' parameter in the open() function? A) The 'newline' parameter is used for file permissions. B) The 'newline' parameter controls file encoding. C) The 'newline' parameter determines the file size. D) The 'newline' parameter specifies how newlines are handled in text files. Show Answer Correct Answer: D) The 'newline' parameter specifies how newlines are handled in text files. 26. The w+ mode to facilitate ..... A) Read only. B) Write only. C) Read and Write. D) Append only. Show Answer Correct Answer: C) Read and Write. 27. Ftell() returns ..... A) Error code. B) Current line. C) Current position of file pointer. D) Size of file. Show Answer Correct Answer: C) Current position of file pointer. 28. In which mode do we open a file for reading and writing binary data? A) 'rb+'. B) 'wb'. C) 'ab+'. D) 'rb'. Show Answer Correct Answer: A) 'rb+'. 29. Which of the following function is used with the csv module in Python to read the contents of a csv file into an object A) Readrows(). B) Csv.write. C) Readrow(). D) Csv.reader. Show Answer Correct Answer: D) Csv.reader. 30. What is the function "w" in file handling A) Read. B) Write. C) Append. D) None of the above. Show Answer Correct Answer: B) Write. 31. How do you allocate memory for an integer variable in C using malloc()? A) Malloc(sizeof(int));. B) Malloc(sizeof(int*));. C) Malloc(int);. D) Malloc(int*);. Show Answer Correct Answer: A) Malloc(sizeof(int));. 32. What is the use of the 'seek' method in file handling? A) The 'seek' method is used to change the file pointer's position in file handling. B) The 'seek' method is used to create a new file. C) The 'seek' method is used to delete a file. D) The 'seek' method is used to read data from a file. Show Answer Correct Answer: A) The 'seek' method is used to change the file pointer's position in file handling. 33. Which of the following is a built-in module in Python? A) Requests. B) Random. C) Numpy. D) Flask. Show Answer Correct Answer: B) Random. 34. What will happen if you try to read from a closed file? A) An error occurs when trying to read from a closed file. B) Reading from a closed file returns an empty string. C) The file will automatically reopen for reading. D) You can still read the last line of the closed file. Show Answer Correct Answer: A) An error occurs when trying to read from a closed file. 35. Which one of the following access mode does not allow writing A) A. B) A+. C) R. D) R+. Show Answer Correct Answer: C) R. 36. Which function is used to move the file position to a desired location within the file? A) Fseek(). B) Rewind(). C) Fweek(). D) Ftell(). Show Answer Correct Answer: A) Fseek(). 37. When reading from text files, which of the following can you use to check ifthe last line of a testfile called (FileA.txt) has been reached? A) WHILE NOT (EOF). B) WHILE NOT ENDOFFILE. C) WHILE NOT EOF (FILEA.txt). D) WHILE NOT (EOF FILEA.txt). Show Answer Correct Answer: C) WHILE NOT EOF (FILEA.txt). 38. What happens if a recursive function does not have a base case? A) It will result in a syntax error. B) It will cause an infinite loop. C) It will terminate prematurely. D) It will return None as the output. Show Answer Correct Answer: B) It will cause an infinite loop. 39. How do you read a character from a file in C using fgetc()? A) File.getc();. B) ReadChar(file);. C) Fgetc(file);. D) GetChar(file);. Show Answer Correct Answer: C) Fgetc(file);. 40. Which method could be used to strip specific characters from the end of a string? A) Remove. B) Strip. C) Estrip. D) Rstrip. Show Answer Correct Answer: D) Rstrip. 41. What is the function used to create a new directory in Python? A) Os.create dir(). B) Os.new dir(). C) Os.mkdir(). D) Os.make dir(). Show Answer Correct Answer: C) Os.mkdir(). 42. What will happen if you open a file in 'w' mode and write to it? A) It will overwrite the existing file contents. B) It will read the file contents. C) It will delete the file. D) It will append the data to the existing file. Show Answer Correct Answer: A) It will overwrite the existing file contents. 43. In which file the data is stored in ASCII and Unicode Characters? A) Binary File. B) Text File. C) Both (a) and (b). D) None of these. Show Answer Correct Answer: B) Text File. 44. What is a stream associated with in C programming? A) Database. B) File. C) Network. D) Memory. Show Answer Correct Answer: B) File. 45. What is the function of feof in file handling? A) To determine if the file has been opened successfully. B) To check if the file has reached the end. C) To read the contents of the file. D) To write data to the file. Show Answer Correct Answer: B) To check if the file has reached the end. 46. What does the 'close()' method do? A) Closes a file. B) Opens a file. C) Reads a file. D) Writes to a file. Show Answer Correct Answer: A) Closes a file. 47. Files are used by programs to store data needed for later use. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 48. The syntax of seek() is:file ..... object.seek(offset[.reference ..... point])what is the default value of reference ..... point? A) 3. B) 0. C) 1. D) 3. Show Answer Correct Answer: B) 0. 49. What does a cursor do in the context of file handling? A) It helps in connecting to the internet. B) It selects text within a document. C) It keeps track of the current location within the file when reading or writing. D) It controls the flow of data to the processor. Show Answer Correct Answer: C) It keeps track of the current location within the file when reading or writing. 50. What is the function of ftell()? A) Gets the current position of the file pointer. B) Checks for end of file. C) Renames a file. D) Deletes a file. Show Answer Correct Answer: A) Gets the current position of the file pointer. 51. Which operator is used to join Path objects in Python? A) . B) -. C) /. D) +. Show Answer Correct Answer: C) /. 52. Code executed based on a condition being true A) Iteration. B) Selection. C) Sequence. D) Variable. Show Answer Correct Answer: B) Selection. 53. To read the next line of the file from the object infi, we use A) Infi.read(all). B) Infi.read(). C) Infi.readline(). D) Infi.readlines(). Show Answer Correct Answer: C) Infi.readline(). 54. The data files can be stored in ..... ways. A) 1. B) 3. C) 4. D) 2. Show Answer Correct Answer: D) 2. 55. Joining elements together to make a string is called what? A) Combining. B) Connecting. C) Stringing. D) Concatenation. Show Answer Correct Answer: D) Concatenation. 56. In fob=open("fruits.txt", 'r'), fob refers to ..... A) File mode. B) File object. C) File type. D) File name. Show Answer Correct Answer: B) File object. 57. If a file is opened using the with statement, what is the main advantage? A) File reading and writing are faster. B) It makes exception handling complex. C) The file is automatically closed after leaving the block. D) The file doesn't need to be opened first. Show Answer Correct Answer: C) The file is automatically closed after leaving the block. 58. Choose the correct output from the options given below:#include struct st { int x; struct st next;}; int main(){ struct st temp; temp.x = 10; temp.next = temp; printf("%d", temp.next.x); return 0;} A) Runtime error. B) 10. C) Garbage Value. D) Compiler error. Show Answer Correct Answer: D) Compiler error. 59. What is file handling in C++ programming? A) Method of handling exceptions in C++. B) Process of working with files. C) Technique for managing memory in C++. D) Approach for creating user interfaces in C++. Show Answer Correct Answer: B) Process of working with files. 60. Structure variable memory is allocated: A) Static only. B) During run time. C) Never. D) During compile time. Show Answer Correct Answer: B) During run time. ← PreviousNext →Related QuizzesScience QuizzesClass 11 QuizzesClass 11 Computer Science Chapter 6 File Handling Quiz 1Class 11 Computer Science Chapter 6 File Handling Quiz 2Class 11 Computer Science Chapter 6 File Handling Quiz 3Class 11 Computer Science Chapter 6 File Handling Quiz 4Class 11 Computer Science Chapter 6 File Handling Quiz 5Class 11 Computer Science Chapter 6 File Handling Quiz 6Class 11 Computer Science Chapter 6 File Handling Quiz 7Class 11 Computer Science Chapter 6 File Handling Quiz 8 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books