This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 10 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 10 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. In fopen("mystory.txt", "r"), what does the mode "r" mean? A) Read and write. B) Write only. C) Read only. D) Append to the file. Show Answer Correct Answer: C) Read only. 2. Assume that size of an integer is 32 bit. What is the output of following program?#includestruct st{ static int x; int y;};int main(){ printf("%zu, sizeof(struct st)); return 0; } A) Runtime error. B) Compile error. C) 4. D) 8. Show Answer Correct Answer: B) Compile error. 3. Which function is best to check if a file exists before opening? A) File.exists(). B) F.check(). C) F.isFile(). D) Os.path.exists(). Show Answer Correct Answer: D) Os.path.exists(). 4. We can manage (create/read/update)CSV files using A) A text editor. B) A Python program. C) A Spreadsheet application. D) All of the above. Show Answer Correct Answer: D) All of the above. 5. Which function is used to read the contents of a file in Python? A) Read. B) Write. C) Open. D) Close. Show Answer Correct Answer: A) Read. 6. What will happen if file.read() is called twice? A) Reads twice. B) Reads same content. C) Second call returns ''. D) Returns error. Show Answer Correct Answer: C) Second call returns ''. 7. This statement terminates the loop containing it. A) End statement. B) Break statement. C) Terminating statement. D) None of the above. Show Answer Correct Answer: B) Break statement. 8. Mention the data type of variable check in the following statements? a. check=f.read()b. check=f.readline()c. check=f.readlines() A) Str b. list c. str. B) Str b. list c. list. C) List b. str c. list. D) Str b. str c. list. Show Answer Correct Answer: D) Str b. str c. list. 9. What is the purpose of the 'os.path.exists()' function? A) To check if a file exists. B) To create a new file. C) To delete a file. D) To open a file. Show Answer Correct Answer: A) To check if a file exists. 10. Which of the following exception is thrown in case when the file specified for writing is not found? A) IOException. B) FileNotFoundException. C) FileException. D) FileInputException. Show Answer Correct Answer: B) FileNotFoundException. 11. What is the result of this code snippet?with open('data.txt', 'r') as f:content = f.read() print(content) A) Prints the entire contents of 'data.txt'. B) Appends data to 'data.txt'. C) Writes data to 'data.txt'. D) Deletes the contents of 'data.txt'. Show Answer Correct Answer: A) Prints the entire contents of 'data.txt'. 12. Apa yang dimaksud dengan file biner? A) File yang hanya berisi teks. B) File yang tidak dapat dibaca. C) File yang berisi data dalam format terstruktur. D) File yang hanya berisi angka. Show Answer Correct Answer: C) File yang berisi data dalam format terstruktur. 13. To read the next line of the file from a file object infi, we use: A) Infi.read(all). B) Infi.read(). C) Infi.readline(). D) Infi.readlines(). Show Answer Correct Answer: C) Infi.readline(). 14. What is the significance of file closing in C++? A) It increases the file size. B) It allows for further writing to the file. C) It has no significance. D) It releases the resources associated with the file, ensures that all the data is written to the file, and prevents any further writing to the file. Show Answer Correct Answer: D) It releases the resources associated with the file, ensures that all the data is written to the file, and prevents any further writing to the file. 15. ..... file is efficient and best way to store information. A) Text file. B) Binary file. C) CSV file. D) Both (a) and (b). Show Answer Correct Answer: B) Binary file. 16. How can you open a file in read and write mode simultaneously in Python? A) Open('file.txt', 'w+'). B) Open('file.txt', 'rw'). C) Open('file.txt', 'a+'). D) Open('file.txt', 'r+'). Show Answer Correct Answer: D) Open('file.txt', 'r+'). 17. In a binary file 'a+' mode is equal to ..... A) Read and write. B) Append only. C) Read only. D) Write only. Show Answer Correct Answer: A) Read and write. 18. What is the purpose of the .strip() method in Python file handling? A) To split the string into multiple parts. B) To remove spaces at the beginning and end of a string. C) To convert the string to uppercase. D) To find a substring within the string. Show Answer Correct Answer: B) To remove spaces at the beginning and end of a string. 19. Appending data to a file places it at the start of the file. A) False. B) True. C) All the above. D) None of the above. Show Answer Correct Answer: A) False. 20. Which function is equivalent to getchar() but requires a file pointer as an argument? A) Putc(). B) Getc(). C) Fread(). D) Fwrite(). Show Answer Correct Answer: B) Getc(). 21. Fread() returns: A) Number of bytes read. B) Characters count. C) Number of items read. D) Only 1 or 0. Show Answer Correct Answer: C) Number of items read. 22. A file is opened in "r+" mode. Which is TRUE? A) Can read but not write. B) Can write but not read. C) Can read and write both. D) Only creates a new file. Show Answer Correct Answer: C) Can read and write both. 23. Which function is used to change the file position in Python? A) Write(). B) Seek(). C) Read(). D) Close(). Show Answer Correct Answer: B) Seek(). 24. What does the 'R' parameter signify when opening a file in Python? A) Execute mode. B) Append mode. C) Read-only mode. D) Write mode. Show Answer Correct Answer: C) Read-only mode. 25. These files are organized by time. A) Serial Files. B) PDF File. C) PNG File. D) None of the above. Show Answer Correct Answer: A) Serial Files. 26. How many types of files are there? A) Three. B) Four. C) Two. D) One. Show Answer Correct Answer: C) Two. 27. To read the next line of the file from a file object fobj, we use: A) Fobj.readlines(). B) Fobj.read(2). C) Fobj.readline(). D) Fobj.read(). Show Answer Correct Answer: C) Fobj.readline(). 28. In f=open( "data.txt" , "r" ), r refers to ..... A) File handle. B) File object. C) File Mode. D) Buffer. Show Answer Correct Answer: C) File Mode. 29. The ..... character is used to separate the values in CSV files. A) . B) :. C) $\rightarrow$. D) ,. Show Answer Correct Answer: D) ,. 30. Which class is used for output file stream operations in C++? A) Ofstream. B) FileStream. C) Fstream. D) Ifstream. Show Answer Correct Answer: A) Ofstream. 31. What does the "w" mode do when opening a file in Python? A) Writes to a file, appends to the file if it exists. B) Writes to a file, reads from the file first. C) Writes to a file, creates the file if it does not exist. D) Writes to a file, error if the file does not exist. Show Answer Correct Answer: C) Writes to a file, creates the file if it does not exist. 32. Which Tkinter widget is used to create a graphical slider for selecting a value? A) Buttons. B) Sliders. C) Label. D) Dialogs. Show Answer Correct Answer: B) Sliders. 33. What does the 'readline()' function do when reading a file in Python? A) It reads the entire file at once. B) It reads the next character in the file. C) It reads the current line from the file and then moves the cursor to the next line. D) It reads the next line from the file. Show Answer Correct Answer: C) It reads the current line from the file and then moves the cursor to the next line. 34. What is the result of using 'a' mode when opening a file? A) It appends to the end of the file. B) It creates a new file only. C) It reads the file. D) It overwrites the file. Show Answer Correct Answer: A) It appends to the end of the file. 35. Which of the following mode will refer to binary data? A) R. B) B. C) W. D) +. Show Answer Correct Answer: B) B. 36. How do you handle errors when working with files in Python? A) Ignore errors and continue execution. B) Use try-except blocks to catch file-related errors such as FileNotFoundError, PermissionError, or IOError in Python. C) Manually modify the Python source code to fix errors. D) Use if-else statements to handle file-related errors. Show Answer Correct Answer: B) Use try-except blocks to catch file-related errors such as FileNotFoundError, PermissionError, or IOError in Python. 37. What is the purpose of the 'write' function in Python file handling? A) To close a file. B) To delete a file. C) To write data to a file. D) To read data from a file. Show Answer Correct Answer: C) To write data to a file. 38. Fstream library provides C++ programmers with ..... classes for working with files A) Four. B) Three. C) Five. D) Two. Show Answer Correct Answer: B) Three. 39. A bunch of bytes stored on some storage device is ..... A) File. B) Data. C) Content. D) File object. Show Answer Correct Answer: A) File. 40. What does the 'break' statement do in C++? A) Pauses the execution of the loop. B) Stops the execution of the loop and exits it. C) Skips the rest of the code inside the loop and continues with the next iteration. D) Breaks the program. Show Answer Correct Answer: B) Stops the execution of the loop and exits it. 41. Which function is used to change the file pointer position? A) Move(). B) Seek(). C) Tell(). D) Jump(). Show Answer Correct Answer: B) Seek(). 42. Which of the following commands can be used to read the entire contents of a file as a string using the file object ? A) Tmpfile.readlines(). B) Tmpfile.readline(). C) Tmpfile.read(). D) Tmpfile.read(n). Show Answer Correct Answer: C) Tmpfile.read(). 43. How can you handle file exceptions in Python? A) Ignore exceptions and continue file processing. B) Always close files without exception handling. C) Use try-except blocks to catch exceptions like FileNotFoundError and IOError when performing file operations. D) Use print statements to debug file operations. Show Answer Correct Answer: C) Use try-except blocks to catch exceptions like FileNotFoundError and IOError when performing file operations. 44. Which method returns the name of the file? A) GetFileName(). B) GetLabel(). C) GetTitle(). D) GetName(). Show Answer Correct Answer: D) GetName(). 45. In Python the default mode while opening the file is ..... A) Write. B) Close. C) Read. D) Append. Show Answer Correct Answer: C) Read. 46. What is the correct order of attributes for a character in the text file as used in the program? A) Health, Stamina, Hunger, Name. B) Stamina, Hunger, Health, Name. C) Name, Stamina, Health, Hunger. D) Name, Health, Stamina, Hunger. Show Answer Correct Answer: D) Name, Health, Stamina, Hunger. 47. Explain the first-fit and best-fit memory allocation techniques. A) First-fit allocates the smallest block, while best-fit allocates the first available block. B) First-fit allocates the largest available block, while best-fit allocates any block. C) First-fit allocates the first suitable memory block, while best-fit allocates the smallest suitable block. D) First-fit allocates memory in a random order, while best-fit uses a fixed size. Show Answer Correct Answer: C) First-fit allocates the first suitable memory block, while best-fit allocates the smallest suitable block. 48. Which method is used to write row by row into a csv file along with writer object? A) Write(). B) Writeline(). C) Writerow(). D) Writer(). Show Answer Correct Answer: C) Writerow(). 49. What is the output of the following code?def greet(name):print("Hello, '' + name)result = greet("John") A) Hello, John. B) Hello, None. C) None. D) Error. Show Answer Correct Answer: A) Hello, John. 50. Class at the top of exception class hierarchy? A) Object. B) Throwable. C) ArithmeticException. D) Exception. Show Answer Correct Answer: B) Throwable. 51. What is a recursive function? A) A function that returns multiple values. B) A function that calls itself. C) A function that takes multiple arguments. D) A function without arguments. Show Answer Correct Answer: B) A function that calls itself. 52. What is the difference between 'r' and 'w' file modes? A) The 'r' mode is for reading and 'w' mode is for appending. B) Both 'r' and 'w' modes are used for reading files only. C) The 'r' mode is for reading, while the 'w' mode is for writing. D) The 'r' mode is for writing, while the 'w' mode is for reading. Show Answer Correct Answer: C) The 'r' mode is for reading, while the 'w' mode is for writing. 53. What does the 'os.path.relpath()' function do? A) Returns a relative path from a start path. B) Lists all files in a directory. C) Returns the absolute path of a file. D) Checks if a path is absolute. Show Answer Correct Answer: A) Returns a relative path from a start path. 54. What letter is added to the modes "r" and "w" to allow them to access non-textual (or binary) information? A) "p". B) "b". C) "d". D) "a". Show Answer Correct Answer: B) "b". 55. Java.lang.NullPointerException is a A) Error. B) Runtime exception. C) Compile time exception. D) None. Show Answer Correct Answer: B) Runtime exception. 56. Which mode should be used to add data to an existing file without deleting its contents? A) APPEND. B) CREATE. C) WRITE. D) READ. Show Answer Correct Answer: A) APPEND. 57. Identify the correct syntax for opening a file A) File object=open("filename"). B) File object=open(filename). C) File object=open(filename). D) None. Show Answer Correct Answer: A) File object=open("filename"). 58. ..... error also known as bug or semantic error A) Compile-time. B) Run time. C) Logical. D) Syntax. Show Answer Correct Answer: C) Logical. 59. FileNotFoundException A) Is a subclass/extends IOException. B) Is a Compile time exception. C) Found in java.io package. D) All. Show Answer Correct Answer: D) All. 60. Select a function which is used to read a single character from a file at a time A) Fscanf(). B) Fgetc(). C) Fgets(). D) Getch(). Show Answer Correct Answer: B) Fgetc(). ← 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