This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 14 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 14 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Differentiate between Absolute Path and Relative Path in file handling. A) Absolute path is always case-sensitive. B) Absolute path includes the root directory, while relative path does not include the root directory. C) Absolute path is shorter than relative path. D) Relative path includes the root directory. Show Answer Correct Answer: B) Absolute path includes the root directory, while relative path does not include the root directory. 2. What is Java serialization? A) It is the process of converting a stream of bytes into an object. B) It is the process of converting an object into a stream of integers. C) It is the process of converting an object into a string of characters. D) It is the process of converting an object into a stream of bytes. Show Answer Correct Answer: D) It is the process of converting an object into a stream of bytes. 3. What type of storage is a file typically stored in? A) Secondary storage. B) Temporary storage. C) Volatile storage. D) Primary storage. Show Answer Correct Answer: A) Secondary storage. 4. What does the "" operator do when used with a function parameter in Python? A) It raises an error because "" is not a valid operator for function parameters. B) It converts the parameter to a string. C) It multiplies the value of the parameter by 2. D) It unpacks an inerrable object into individual arguments. Show Answer Correct Answer: D) It unpacks an inerrable object into individual arguments. 5. What does 'a+' means in file handling? A) Overwrite. B) Append. C) Append and read. D) Write and read. Show Answer Correct Answer: C) Append and read. 6. Where is data typically stored to ensure it is external to the program's main data? A) Secondary Storage. B) Internal Memory. C) Primary Storage. D) Cloud Storage. Show Answer Correct Answer: A) Secondary Storage. 7. Spaces, tabs, new lines are the example of ..... A) White spaces. B) Empty Spaces. C) Null values. D) None of these. Show Answer Correct Answer: A) White spaces. 8. What method is used to check if a file exists? A) IsExisting(). B) Exists(). C) IsPresent(). D) IsAvailable(). Show Answer Correct Answer: B) Exists(). 9. It opens the file for a read. A) Ios::out. B) Ios::ate. C) Ios::in. D) Ios::trunc. E) Ios::app. Show Answer Correct Answer: C) Ios::in. 10. Which Is data type of file pointer is ..... A) File. B) Double. C) Int. D) Char. Show Answer Correct Answer: A) File. 11. What will be the output of the following Python code?def getMonth(m):if m <1 or m>12:raise ValueError("Invalid")print(m)getMonth(6) A) ValueError. B) Invalid. C) 6. D) ValueError( "Invalid" ). Show Answer Correct Answer: C) 6. 12. What happens if the data in the text file is not in the expected format? A) The program outputs incorrect data. B) The program deletes the file. C) The program will not run. D) The program requests user re-input. Show Answer Correct Answer: A) The program outputs incorrect data. 13. Class IT{static public void main(String ..... args){String s=null;System.out.println("length is:"+s.length());}} A) Output is 0. B) It throws NullPointerException. C) It throws IOException. D) It throws StringExeption. Show Answer Correct Answer: B) It throws NullPointerException. 14. The output sent to the file is appended to it. A) Ios::trunc. B) Ios::ate. C) Ios::out. D) Ios::app. E) Ios::in. Show Answer Correct Answer: D) Ios::app. 15. File is created if does not exist. If the file exists, file is truncated( past data is lost). Both reading and writing operation can take place. What is the text file mode? A) 'w+'. B) 'w'. C) 'r'. D) 'a+'. Show Answer Correct Answer: A) 'w+'. 16. What does the 'read()' function do? A) Deletes the contents of a file. B) Reads all the text in a file. C) Writes text to a file. D) Closes the file. Show Answer Correct Answer: B) Reads all the text in a file. 17. Which method is used to set the file handle's position within a file? A) Search(). B) Search(. C) Seek(). D) Tell(). Show Answer Correct Answer: C) Seek(). 18. Which function is used to count or display words from a file? A) Split(). B) Print(count). C) Count=count+1. D) Len(L). Show Answer Correct Answer: A) Split(). 19. File.seek(0) followed by file.read() will: A) Re-read file from start. B) Skip file. C) Overwrite. D) Raise error. Show Answer Correct Answer: A) Re-read file from start. 20. What is the first file handling operation mentioned in the text? A) Read. B) Close. C) Write. D) Open. Show Answer Correct Answer: D) Open. 21. What does the 'open' command do in Python file handling? A) It closes the file. B) It opens the file for reading or writing. C) It creates a new file. D) It reads the file. Show Answer Correct Answer: B) It opens the file for reading or writing. 22. What will be the output of the following code?def add(a, b):return a + bprint(add(5, 7)) A) 57. B) 12. C) Error. D) None. Show Answer Correct Answer: B) 12. 23. Which method is used to read the entire contents of a file in Python? A) Write(). B) Seek(). C) Close(). D) Read(). Show Answer Correct Answer: D) Read(). 24. What will be the output of the following C code#include union temp { int a; float b; char c; }; int main() { union temp s = {1, 2.5, 'A'}; printf("%c", s.c); return 0; } A) 'A'. B) Compilation error. C) '1'. D) Nothing. Show Answer Correct Answer: B) Compilation error. 25. What is the function used to read from a file in Python? A) Read(). B) Load(). C) Write(). D) Open(). Show Answer Correct Answer: D) Open(). 26. How can you read from a file in Python? A) Open('file.txt', 'w').read(). B) Open('file.txt', 'r').read(). C) Read('file.txt'). D) File.open('file.txt', 'read'). Show Answer Correct Answer: B) Open('file.txt', 'r').read(). 27. What is the function used to check if a file exists in Python? A) Os.path.exist(). B) Check.file(). C) File.exist(). D) Os.path.exists(). Show Answer Correct Answer: D) Os.path.exists(). 28. What is the significance of the 'rb' mode when opening a binary file? A) It indicates that the file is being opened in write mode for binary data. B) It signifies that the file is being opened in append mode for binary data. C) It specifies that the file is being opened in read mode for text data. D) It signifies that the file is being opened in read mode specifically for binary data. Show Answer Correct Answer: D) It signifies that the file is being opened in read mode specifically for binary data. 29. What does the 'readlines' method do in Python file handling? A) Reads every line from the file one at a time. B) Reads the entire file at once. C) Reads a specific line from the file. D) Reads a single line from the file. Show Answer Correct Answer: A) Reads every line from the file one at a time. 30. To read 4th line from text file, which of the following statement is true? A) Dt = f.readlines();print(dt[3]). B) Dt=f.read(4) ;print(dt[3]). C) Dt=f.readline(4);print(dt[3]). D) All of these. Show Answer Correct Answer: A) Dt = f.readlines();print(dt[3]). 31. What is the significance of file modes in file handling? A) File modes are significant because they control access permissions and operations on files, ensuring data integrity and appropriate handling. B) File modes dictate the file format type. C) File modes determine the size of the file. D) File modes are used to compress files for storage. Show Answer Correct Answer: A) File modes are significant because they control access permissions and operations on files, ensuring data integrity and appropriate handling. 32. Which one of these variables has an illegal name? A) $ myVar. B) $ my Var. C) $ my-Var. D) $ myVar. Show Answer Correct Answer: C) $ my-Var. 33. What does the os.path.isfile() function return if the file does not exist? A) True. B) False. C) Error. D) None. Show Answer Correct Answer: B) False. 34. Which of the following modes allows both reading and writing to a file? A) R. B) A. C) W. D) R+. Show Answer Correct Answer: D) R+. 35. Ravi opened a file in a certain mode. After opening the file, he forgot the mode. One interesting fact about that mode is '' If the file already exists, all the contents will be overwritten" . Help him to identify the correct mode. A) Read mode. B) Write mode. C) Append mode. D) Binary and read mode. Show Answer Correct Answer: B) Write mode. 36. What is the index of the last character in a string? A) 0. B) -1. C) 1. D) None of the above. Show Answer Correct Answer: B) -1. 37. What are some common use cases for binary files in programming? A) Creating web pages. B) Writing scripts for automation. C) Storing plain text files. D) Common use cases for binary files include storing images, audio files, video files, executable programs, and serialized data. Show Answer Correct Answer: D) Common use cases for binary files include storing images, audio files, video files, executable programs, and serialized data. 38. What happens if you try to write to a file that does not exist? A) The file is ignored and no action is taken. B) The file is created and then written to. C) The file is opened in read-only mode. D) The file cannot be created and an error is thrown. Show Answer Correct Answer: B) The file is created and then written to. 39. What does ftell() function return in C? A) Current position of the file pointer. B) Number of lines in the file. C) Size of the file. D) Total bytes in the file. Show Answer Correct Answer: A) Current position of the file pointer. 40. What is the data type of data read to and from a file? A) Boolean. B) Integer. C) String. D) Real. Show Answer Correct Answer: C) String. 41. Which of the following is used to read all lines in a file as a list? A) Read(). B) Readline(). C) Readlines(). D) All(). Show Answer Correct Answer: C) Readlines(). 42. If we want to add new data without overwriting the previous content then we should write using ..... mode A) "w". B) "r". C) "a". D) None. Show Answer Correct Answer: C) "a". 43. What is the purpose of the 'close()' function in programming languages when working with files? A) To delete the file from the system. B) To save changes to the file. C) To close the file and ensure all operations are complete. D) To open a new file. Show Answer Correct Answer: C) To close the file and ensure all operations are complete. 44. Which of the following is not a standard exception in Python? A) ValueError. B) NameError. C) AssignmentError. D) IOError. Show Answer Correct Answer: C) AssignmentError. 45. Which Python function is used to open a text file for reading? A) Open("file.txt", "w"). B) Open("file.txt", "r"). C) Write("file.txt"). D) Read("file.txt"). Show Answer Correct Answer: B) Open("file.txt", "r"). 46. A binary file stores information in ASCII or Unicode characters. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 47. In which scenario would you use the 'APPEND' mode? A) To read data from a file. B) To add new data at the end of a file. C) To create a new file. D) To overwrite existing data. Show Answer Correct Answer: B) To add new data at the end of a file. 48. Which mode in Python is used to open a file for reading? A) W. B) X. C) A. D) R. Show Answer Correct Answer: D) R. 49. How can you read a file using a context manager? A) Use 'open(filename)' to read a file. B) Read a file by calling 'file.read()' directly. C) Use 'with open(filename, mode) as file:' to read a file. D) Use 'open(filename, mode)' without 'with' to read a file. Show Answer Correct Answer: C) Use 'with open(filename, mode) as file:' to read a file. 50. The ..... character is used to seprate the values in TSV files. A) . B) :. C) ,. D) $\rightarrow$. Show Answer Correct Answer: D) $\rightarrow$. 51. Kamut accidentally used "w" mode on a project file that contains important information. What is the immediate risk? A) The file becomes read-only. B) The file might get locked. C) The existing file content will be permanently erased. D) The file will not open at all. Show Answer Correct Answer: C) The existing file content will be permanently erased. 52. Files need to be closed when using file handling in order to save data A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 53. What does the 'read ..... text()' method do? A) Writes text to a file. B) Reads the contents of a text file as a string. C) Creates a new text file. D) Deletes the contents of a text file. Show Answer Correct Answer: B) Reads the contents of a text file as a string. 54. The read() is indicate ..... A) Read a particular byte. B) Read a line. C) Read a lines. D) All these. Show Answer Correct Answer: A) Read a particular byte. 55. What is the use of tell() method in Python? A) The tell() method writes data to a file. B) The tell() method closes the file object. C) The tell() method opens a file for reading. D) The tell() method returns the current position of the file cursor in a file object. Show Answer Correct Answer: D) The tell() method returns the current position of the file cursor in a file object. 56. Which function is used to close the file? A) Close(). B) End(). C) Terminate. D) None. Show Answer Correct Answer: A) Close(). 57. Which command is used to close an open file in a program? A) CLOSEFILE. B) OPENFILE. C) WRITEFILE. D) READFILE. Show Answer Correct Answer: A) CLOSEFILE. 58. What is the difference between absolute and relative paths? A) Absolute paths begin with the root folder, relative paths do not. B) Both are the same. C) Relative paths are longer. D) Absolute paths are only for Windows. Show Answer Correct Answer: A) Absolute paths begin with the root folder, relative paths do not. 59. Which step is necessary after writing to a file? A) Rename the file. B) Open the file. C) Close the file. D) Delete the file. Show Answer Correct Answer: C) Close the file. 60. What is a CSV file and how is it different from a text file? A) A CSV file is a database format that requires special software to read. B) A CSV file is a structured text file that organizes data in rows and columns using commas as delimiters, while a text file is an unstructured file that can contain any text. C) A CSV file is a type of image file used for graphics. D) A CSV file is a binary file that cannot be opened in a text editor. Show Answer Correct Answer: B) A CSV file is a structured text file that organizes data in rows and columns using commas as delimiters, while a text file is an unstructured file that can contain any text. ← 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