This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 21 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 21 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which method is used to deserialize object from binary file? A) Load(). B) Dump(). C) Unpickle(). D) Readobj(). Show Answer Correct Answer: A) Load(). 2. Apa yang terjadi apabila user mencoba membuka file yang tidak tersedia dengan menggunakan fungsi open() dan mode "x" ? A) Program akan memunculkan Error berupa FileNotFoundError. B) Program akan membuat file baru sesuai filepath yang diminta. C) Program akan memunculkan Error berupa FileExistsError. D) Program akan mengembalikan string kosong. Show Answer Correct Answer: B) Program akan membuat file baru sesuai filepath yang diminta. 3. How can you write data to a file in binary mode? A) Use open('filename', 'r') to write binary data. B) Use open('filename', 'ab') to write binary data. C) Use open('filename', 'wb') to write binary data. D) Use open('filename', 'w') to write binary data. Show Answer Correct Answer: C) Use open('filename', 'wb') to write binary data. 4. The separator character which is used in csv file is called as ..... A) Semicolon. B) Delimiter. C) Tab space. D) Colon. Show Answer Correct Answer: B) Delimiter. 5. Which of the following is a benefit of using the 'with' statement for file operations? A) It automatically deletes the file after use. B) It automatically handles opening and closing the file. C) It allows multiple files to be opened simultaneously. D) It prevents the file from being modified. Show Answer Correct Answer: B) It automatically handles opening and closing the file. 6. Which of the following is not a file handling method A) Append. B) Read. C) Write. D) Remove. Show Answer Correct Answer: D) Remove. 7. What does the "x" mode do when opening a file in Python? A) Creates the specified file, error if the file does not exist. B) Creates the specified file, appends to the file if it exists. C) Creates the specified file, returns an error if the file exists. D) Creates the specified file, truncates the file first. Show Answer Correct Answer: C) Creates the specified file, returns an error if the file exists. 8. Can we read file without opening. (T/F) A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 9. How do you write "Hello, world!" to a file in Python? A) File.writelines("Hello, world!"). B) File.save("Hello, world!"). C) File.writeText("Hello, world!"). D) File.write("Hello, world!"). Show Answer Correct Answer: D) File.write("Hello, world!"). 10. Try:a=10/5 print (a) except ArithmeticError:print ("This statement is raising an exception" )finally:print (" final block executed '' ) A) This statement is raising an exceptionfinal block executed. B) 2.0 final block executed. C) Final block executed. D) 2.0. Show Answer Correct Answer: B) 2.0 final block executed. 11. A collection of characters that is written or read during file handling in C++ is called A) Stream. B) Numbers. C) Bits. D) Variable. Show Answer Correct Answer: A) Stream. 12. I want an array that stores values between 2 and 5, which of the following is correct? A) MyArray[2 to 5]. B) MyArray2 to 5. C) MyArray{2 to 5}. D) MyArray[5]. Show Answer Correct Answer: A) MyArray[2 to 5]. 13. Which mode truncates the file to zero length? A) "r". B) "a". C) "w". D) "r+". Show Answer Correct Answer: C) "w". 14. Which function is used to read single line from file? A) Readlines(). B) Read(n). C) Readline(). D) Readline(1). Show Answer Correct Answer: C) Readline(). 15. While appending the data to the binary file, the mode should be ..... A) 'a+'. B) 'ab'. C) 'w+'. D) 'w'. E) 'a'. Show Answer Correct Answer: B) 'ab'. 16. What is the main purpose of file handling in programming? A) To create images. B) To save and retrieve data. C) To design websites. D) To play music. Show Answer Correct Answer: B) To save and retrieve data. 17. What is the purpose of the 'struct' module in binary file handling? A) The 'struct' module is designed for handling text files only. B) The 'struct' module provides functions for database management. C) The 'struct' module is used for creating graphical user interfaces. D) The 'struct' module facilitates the handling of binary data by providing functions to pack and unpack data into and from binary formats. Show Answer Correct Answer: D) The 'struct' module facilitates the handling of binary data by providing functions to pack and unpack data into and from binary formats. 18. Discuss the importance of error handling in file operations in Python. A) Ignoring errors in file operations leads to better performance. B) Error handling in file operations is not necessary in Python. C) Handling errors in file operations can introduce more bugs. D) Error handling in file operations is important in Python to prevent program crashes and handle exceptions gracefully. Show Answer Correct Answer: D) Error handling in file operations is important in Python to prevent program crashes and handle exceptions gracefully. 19. What happens when a piece of data is written to a file? A) Data is copied from a variable in RAM to a file. B) Data is copied from a variable in the program to a file. C) Data is copied from the program to a file. D) Data is copied from a file object to a file. Show Answer Correct Answer: A) Data is copied from a variable in RAM to a file. 20. Function used to read all the content of file in the form of list: A) Readline(). B) Read lines(). C) Readlines(). D) Read(). Show Answer Correct Answer: C) Readlines(). 21. A CSV file is also known as a A) 3D File. B) String file. C) Flat file. D) Random file. Show Answer Correct Answer: C) Flat file. 22. Which are the different ways to read data from the keyboard? A) Scanner. B) InputStreamReader. C) DataInputStream. D) All of given. Show Answer Correct Answer: D) All of given. 23. What is the method used to reassign the standard input stream in Python? A) Sys.stdin.readline(). B) Sys.stdin.write(). C) Reassigning sys.stdin. D) Input(). Show Answer Correct Answer: C) Reassigning sys.stdin. 24. Fprintf() is used to write: A) Formatted output. B) Strings only. C) Binary only. D) Characters only. Show Answer Correct Answer: A) Formatted output. 25. Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist? A) 'a'. B) 'e'. C) 'w'. D) 'r'. Show Answer Correct Answer: C) 'w'. 26. How do you read a text file line by line in Python? A) Use 'open("filename.txt") as file:read(file)'. B) Use 'with open("filename.txt") as file:for line in file:print(line)'. C) Use 'file.read lines("filename.txt")'. D) Use 'open("filename.txt") and file.readlines()'. Show Answer Correct Answer: B) Use 'with open("filename.txt") as file:for line in file:print(line)'. 27. The ..... and ..... functions work identically with the text file as well as binary file A) Try(), Except(). B) Tell(), seek(). C) Pickle(), Unpickle(). D) Dump(), Load(). Show Answer Correct Answer: B) Tell(), seek(). 28. Which of the following function you can use to write data in the binary format? A) Loadbinary(). B) Sendbinary(). C) Load(). D) Dump(). Show Answer Correct Answer: D) Dump(). 29. Which method returns the absolute pathname of a file? A) GetPath(). B) GetAbsolutePath(). C) GetDirectory(). D) GetFullPath(). Show Answer Correct Answer: B) GetAbsolutePath(). 30. How do you close a file in C++? A) End(). B) Terminate(). C) Close(). D) Finish(). Show Answer Correct Answer: C) Close(). 31. Urutan langkah file yang benar menurut gambar adalah apa? A) Proses, tutup, buka, deklarasi. B) Tutup, deklarasi, proses, buka. C) Deklarasi, buka, proses, tutup. D) Buka, proses, tutup, deklarasi. Show Answer Correct Answer: C) Deklarasi, buka, proses, tutup. 32. What is the output of the following recursive function?def countdown(n):if n <= 0:print("Blastoff!")else:print(n, end=" ")countdown(n-1)countdown(5) A) Blastoff!. B) Error. C) 1 2 3 4 5 Blastoff!. D) 5 4 3 2 1 Blastoff!. Show Answer Correct Answer: D) 5 4 3 2 1 Blastoff!. 33. To close a file we use: A) File end(). B) Endfile(). C) Close(). D) Fclose(). Show Answer Correct Answer: D) Fclose(). 34. What is the purpose of the 'writeline' function? A) To write a line to a file. B) To close a file. C) To delete a line from a file. D) To read a line from a file. Show Answer Correct Answer: A) To write a line to a file. 35. Which statement is true regarding the use of loops in file handling? A) For aLine in aFile statement can be used to iterate over a list. B) Loops cannot be used to read files. C) A loop is an efficient and clear way to read each line in a file until the end. D) Files should always be read in one go, not using loops. Show Answer Correct Answer: C) A loop is an efficient and clear way to read each line in a file until the end. 36. What is the extension for binary files? A) .txt. B) .csv. C) .CSV. D) .dat. Show Answer Correct Answer: D) .dat. 37. Class IT{static public void main(String ..... args){int k=Integer.parseInt(args[0]);System.out.println(k);}}if args[0]="gec" then what type of exception is thrown by the above program. A) ArrayIndexOutOfBoundsException. B) NullPointerException. C) NumberFormatException. D) InvalidStringException. Show Answer Correct Answer: C) NumberFormatException. 38. Which function is used to move pointer to a specific byte? A) Seek(). B) Move(). C) Position(). D) Locate(). Show Answer Correct Answer: A) Seek(). 39. What is the difference between reading and writing to a file? A) Reading retrieves data, writing adds or updates data. B) Reading deletes data, writing appends data. C) Reading updates data, writing retrieves data. D) Reading adds data, writing retrieves and updates data. Show Answer Correct Answer: A) Reading retrieves data, writing adds or updates data. 40. Pointer to structure uses: A) P.field. B) Struct.p. C) Struct$\rightarrow$field. D) P$\rightarrow$field. Show Answer Correct Answer: D) P$\rightarrow$field. 41. What is the Binary file mode for the Description read and write? A) Wb. B) R+b or rb+. C) Rb. D) W+b or wb+. Show Answer Correct Answer: B) R+b or rb+. 42. What happens if you use fopen("newfile.txt", "w") on a non-existing file? A) The file will be deleted. B) PHP will show an error. C) The file will be created. D) Nothing will happen. Show Answer Correct Answer: C) The file will be created. 43. What will be the output of the following C code? #include int main() { FILE *fp = stdout; int n; fprintf(fp, "%d ", 45); fflush(stdout); fprintf(stderr, "%d", 65); return 0; } A) 45 65. B) 45. C) Compilation error. D) 65 45. Show Answer Correct Answer: A) 45 65. 44. ..... is the inverse of Pickling where a byte stream is converted into an object hierarchy. A) Un Pickling. B) Serialization. C) Tell(). D) Seek(). Show Answer Correct Answer: A) Un Pickling. 45. Which of the following is not a known file type? A) ....dat. B) Csv. C) Bin. D) Txp. Show Answer Correct Answer: D) Txp. 46. What is a file path? A) Shows where a file is located. B) Indicates the size of a file. C) Defines the file type. D) A method to save files. Show Answer Correct Answer: A) Shows where a file is located. 47. What type of file access jumps directly to any piece of data in a file without reading the data that came before it? A) Sequential. B) Random. C) Number. D) Text. Show Answer Correct Answer: B) Random. 48. How do you change the file position to an offset value from the start? A) Fp.seek(offset, 0). B) Fp.seek(offset, 1). C) Fp.seek(offset, 2). D) None of the mentioned. Show Answer Correct Answer: A) Fp.seek(offset, 0). 49. Which of the following is a step in file handling? A) Copy the file. B) Delete the file. C) Rename the file. D) Open the file. Show Answer Correct Answer: D) Open the file. 50. What will be the output of the following code snippet?f=open('xyz.txt', 'r')x=f.read()f.close()print(x) A) Error(not writable). B) Error(not readable). C) It will read all the data of the file. D) None. Show Answer Correct Answer: C) It will read all the data of the file. 51. What is the output of the following code?def func(a, b=10, c=20):return a + b + cresult = func(5, c=15)print(result) A) 50. B) 30. C) Error. D) 25. Show Answer Correct Answer: B) 30. 52. What command can you use to send back data from a function? A) Sendback. B) Return. C) Print(). D) Back. Show Answer Correct Answer: B) Return. 53. Koju metodu koristimo za zatvaranje streama preko objekta file u C++? A) File.stop();. B) File.end();. C) File.close();. D) File.exit();. Show Answer Correct Answer: C) File.close();. 54. Which method in the csv module is used to write a single row to a csv file? A) Csv.write row. B) Row to csv(). C) Csv.writerow. D) Writecsvrow(). Show Answer Correct Answer: C) Csv.writerow. 55. Which function is used to open a file in C++ for reading or writing? A) Ofstream() / ifstream(). B) CreateFile(). C) Open(). D) OpenFile(). Show Answer Correct Answer: C) Open(). 56. What does the 'W' parameter signify in the 'open' command when opening a file in Python? A) Wipe the file. B) Wait for input from the file. C) Write to the file. D) Wrap the file. Show Answer Correct Answer: C) Write to the file. 57. Which module is used to serialize objects in Python? A) Shelve. B) Pickle. C) Os. D) Json. Show Answer Correct Answer: A) Shelve. 58. How can you ensure user input is treated as a string? A) Use the str() function to convert input to a string. B) Use the int() function to convert input to an integer. C) Use the input() function without conversion. D) Store input in a variable without any changes. Show Answer Correct Answer: A) Use the str() function to convert input to a string. 59. What is the correct syntax of open() function? A) File name = open(file name [, access mode][, buffering]). B) File object = open(file name [, access mode][, buffering]). C) File object = open(file name). D) None of the above. Show Answer Correct Answer: B) File object = open(file name [, access mode][, buffering]). 60. Apa yang harus dilakukan setelah selesai menggunakan file? A) Menghapus file. B) Menulis data ke file. C) Menutup file. D) Membaca file. Show Answer Correct Answer: C) Menutup file. ← 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