This quiz works best with JavaScript enabled. Home > Cbse > Class 11 > Science > Computer Science > Class 11 Computer Science Chapter 6 File Handling – Quiz 20 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 20 (60 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. (1) which do we use to output information to a file opened under w/a mode? (2) what data type does it accept as an argument? A) .send(), any type. B) .write(), string. C) .write(), any type. D) .send(), string. Show Answer Correct Answer: B) .write(), string. 2. Which of the following is method for testing whether the specified element is a file or a directory? A) IsFile(). B) IsFile(). C) Isfile(). D) Isfile(). Show Answer Correct Answer: A) IsFile(). 3. The ..... statement means to place the file pointer at 30 bytes behind(backward direction) from end of file. A) F.seek(-30, 2). B) F.seek(30, 2). C) F.seek(30, 1). D) F.seek(-30, 1). Show Answer Correct Answer: A) F.seek(-30, 2). 4. Which file extension is used for a plain text file? A) .jpg. B) .txt. C) .pdf. D) .exe. Show Answer Correct Answer: B) .txt. 5. To iterate through an array in a file, I would use A) Selection. B) Sequence. C) A for loop. D) A while loop. Show Answer Correct Answer: C) A for loop. 6. Choose the right statement for fscanf() and scanf() A) Fscanf() can read from standard input whereas scanf() specifies a stream from which to read. B) Fscanf() can specifies a stream from which to read whereas scanf() can read only from standard input. C) Fscanf() and scanf() has no difference in their functions. D) Fscanf() and scanf() can read from specified stream. Show Answer Correct Answer: B) Fscanf() can specifies a stream from which to read whereas scanf() can read only from standard input. 7. What is the correct way to write to a file in Python? A) File = open('file.txt', 'r'). B) File = open('file.txt', 'x'). C) File = open('file.txt', 'a'). D) File = open('file.txt', 'w'). Show Answer Correct Answer: D) File = open('file.txt', 'w'). 8. Exception classes belongs to following package A) Import java.io.*. B) Import java.lang.Exception.*. C) Import java.util.*. D) Import java.lang.*. Show Answer Correct Answer: D) Import java.lang.*. 9. What is the correct function to read a specific number of bytes from an open file? A) Readfile(). B) Fwrite(). C) Fread(). D) Fopen(). Show Answer Correct Answer: C) Fread(). 10. What type of objects allow us to use the "with" term? A) Those with a close() method. B) Those that contain the obj definition. C) Only those that are variables. D) Those that are related to files. Show Answer Correct Answer: A) Those with a close() method. 11. A ..... governs the type of operations(eg read/write/append) possible in the opened file.The two types of data files can be ..... files and ..... files. A) File mode, Text, Data. B) Data, Text, record. C) FILEMODE, EXCEL, WORD. D) File Mode, read, write. Show Answer Correct Answer: A) File mode, Text, Data. 12. Files store data permanently in a/ an A) Function. B) Array. C) Variable. D) Storage device. Show Answer Correct Answer: D) Storage device. 13. Which of the following statements is correct regarding the seek() method? A) Sets the file's current position at the offset. B) Position of file pointer remains unchanged. C) The file pointer is set to the start of the file. D) Sets the file position to the end of file. Show Answer Correct Answer: A) Sets the file's current position at the offset. 14. Module used to read and write into binary files A) Open. B) Dump. C) Load. D) Pickle. Show Answer Correct Answer: D) Pickle. 15. In the data hierarchy, it is also considered as the Binary. A) Records. B) Characters. C) Bits. D) Fields. Show Answer Correct Answer: C) Bits. 16. What will be the output of the following C code? (Given that the size of array is 4 and new size of array is 5)#include#includemain(){ int *p, i, a, b; printf("Enter size of array: "); scanf("%d", &a); p=(int*)malloc(a*sizeof(int)); for(i=0;i A) 0123. B) Error. C) 01230. D) 01234. Show Answer Correct Answer: C) 01230. 17. Which of the following functions do use use to write data in the binary format ..... A) Dump(). B) Write(). C) Seek(). D) Load(). Show Answer Correct Answer: A) Dump(). 18. Which function is used to read the content of Binary files? A) Dump(). B) Load(). C) Both a and b. D) None. Show Answer Correct Answer: B) Load(). 19. 'r' mode overwrites any data in the file A) TRUE. B) FALSE. C) All the above. D) None of the above. Show Answer Correct Answer: B) FALSE. 20. Which mode will create a file only if it doesn't already exist? A) 'w'. B) 'a'. C) 'x'. D) 'r'. Show Answer Correct Answer: C) 'x'. 21. Assertion:Python is said to have broadly two types of files-binary and text files, even when there are CSV and TSV files also Reason:The CSV and TSV are types of delimited text only where the delimiters are common and tab respectively. A) Both A and R are true and R is the correct explanation of A. B) Both A and R are true and R is not the correct explanation of A. C) A is true but R is false (or partly true). D) A is false (or partly true) but R is true. Show Answer Correct Answer: A) Both A and R are true and R is the correct explanation of A. 22. If file is opened in "ab" mode, what happens? A) Overwrites file. B) Appends binary data at end. C) Reads and writes. D) Error. Show Answer Correct Answer: B) Appends binary data at end. 23. Which keyword is used to catch exceptions in Python? A) Try. B) Except. C) Finally. D) Raise. Show Answer Correct Answer: B) Except. 24. In Python how many function that help you manipulate the position of file pointer A) 4. B) 3. C) 2. D) 1. Show Answer Correct Answer: C) 2. 25. What will happen if you try to open a non-existent file in read mode? A) The file will be opened successfully. B) The file will be opened in write mode. C) A new file will be created. D) The program will raise an error. Show Answer Correct Answer: D) The program will raise an error. 26. How do you read a specific row from a CSV file? A) Read the CSV using NumPy and select the row with np.row[row index]. B) Use CSV reader to load the file and print the row directly. C) Use pandas to read the CSV and access the row with df.iloc[row index]. D) Open the CSV in Excel and manually find the row you need. Show Answer Correct Answer: B) Use CSV reader to load the file and print the row directly. 27. With open("hello.txt", "w") as f:f.write("Hello World how are you today") with open('hello.txt', 'r') as f:data = f.readlines() for line in data:words = line.split() print (words) f.close() A) Hello World how are you today. B) Runtime Error. C) ['Hello', 'World', 'how', 'are', 'you', 'today']. D) Hello. Show Answer Correct Answer: C) ['Hello', 'World', 'how', 'are', 'you', 'today']. 28. What is the output of 'os.path.abspath('.')'? A) The home directory. B) The root directory. C) The current working directory. D) The parent directory. Show Answer Correct Answer: C) The current working directory. 29. Opening a file with write access causes the contents of the file to removed first. A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: A) True. 30. Which function is used to read all characters and return it in form a string? A) Read(). B) Readall(). C) Readchars(). D) Readlines(). Show Answer Correct Answer: A) Read(). 31. The text files stores information in the form of ..... A) ASCII. B) UNICODE. C) Both A and B. D) None of this. Show Answer Correct Answer: C) Both A and B. 32. What does the 'os.path.getsize()' function return? A) The size of the file path. B) The size of a directory. C) The size of a file in bytes. D) The total size of all files in a directory. Show Answer Correct Answer: C) The size of a file in bytes. 33. The two writing functions for python text files are ..... and ..... A) Write() and writeline(). B) Write()and writelines(). C) Writerow() and writerows(). D) Dump() and load(). Show Answer Correct Answer: B) Write()and writelines(). 34. When reading a line from a text file called file.txt into a variable called linetext, which of the following should we use? A) READFILE (linetext, file.txt). B) READFILE (file.txt) linetext. C) READFILE (file.txt, linetext). D) READFILE file.txt, linetext. Show Answer Correct Answer: D) READFILE file.txt, linetext. 35. What does the 'READ' mode do when a file is opened in this mode? A) Overwrites data in the file. B) Deletes the file. C) Adds data to the file. D) Reads data from the file. Show Answer Correct Answer: D) Reads data from the file. 36. Fwrite() returns: A) Number of items written. B) Number of characters written. C) Nothing. D) -1 when error. Show Answer Correct Answer: A) Number of items written. 37. What is virtual memory and how does it work? A) Virtual memory is a memory management technique that uses disk space to extend RAM, allowing for larger applications to run. B) Virtual memory is a type of physical storage that increases CPU speed. C) Virtual memory is a technique that compresses RAM to save space. D) Virtual memory is a method that uses network resources to enhance processing power. Show Answer Correct Answer: A) Virtual memory is a memory management technique that uses disk space to extend RAM, allowing for larger applications to run. 38. The method to set the file marker position. A) Search(). B) Seek(). C) Seek(. D) Search(. Show Answer Correct Answer: B) Seek(). 39. The ..... statement is used to execute as a pair operations. A) Seek(). B) Unpicked. C) Pickle. D) With. Show Answer Correct Answer: D) With. 40. Which function is used to delete a file? A) Deletefile(). B) Fdelete(). C) Remove(). D) Unlink(). Show Answer Correct Answer: C) Remove(). 41. Which functions is used to write all the characters? A) Write(). B) Writecharacters(). C) Writeall(). D) Writechar(). Show Answer Correct Answer: A) Write(). 42. How many file objects would you need to manage the following situations:(a) to process four files sequentially (b) To process two sorted files into third file A) 2, 4. B) 4, 3. C) 4, 2. D) 3, 4. Show Answer Correct Answer: B) 4, 3. 43. If mode argument not passed, then Python will assume it to be ..... by default A) W. B) W+. C) R+. D) R. Show Answer Correct Answer: D) R. 44. Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing? A) File =open("Record.dat", "rb+"). B) File =open("Record.dat", "wb"). C) File =open("Record.dat", "ab"). D) File =open("Record.dat", "rb"). Show Answer Correct Answer: A) File =open("Record.dat", "rb+"). 45. Name the error which occurs if the file does not exist when it is opened in 'r' mode A) EOFError. B) Unexpectederror. C) I/OError. D) FileNotFoundError. Show Answer Correct Answer: D) FileNotFoundError. 46. If there is fopen function in program then there should always be A) Fread() . B) Fwrite(). C) Fclose(). D) None. Show Answer Correct Answer: C) Fclose(). 47. How do you release dynamically allocated memory in C using free()? A) Free(ptr);. B) DeleteMemory(ptr);. C) ReleaseMemory(ptr);. D) Delete(ptr);. Show Answer Correct Answer: A) Free(ptr);. 48. What is the difference between FileWriter and Fileoutputstream in Java? A) FileWriter is used to read bytes from a file, while FileOutputStream is used to write characters to a file. B) FileWriter and FileOutputStream are not related to file handling in Java. C) FileWriter is used to write characters to a file, while FileOutputStream is used to write bytes to a file. D) FileWriter and FileOutputStream are used interchangeably in Java. Show Answer Correct Answer: C) FileWriter is used to write characters to a file, while FileOutputStream is used to write bytes to a file. 49. The ..... statement is a statement which combines the opening of your file and the processing of a file along multiple exception handling. A) With. B) Load. C) Try. D) Seek. Show Answer Correct Answer: A) With. 50. When should you use the flush() function in Python file handling? A) 3. Use file buffering. B) 2. Use file pointers. C) 1. Use file streams. D) When you want to ensure that all the data written to a file is physically saved on the disk immediately without waiting for the buffer to fill up. Show Answer Correct Answer: D) When you want to ensure that all the data written to a file is physically saved on the disk immediately without waiting for the buffer to fill up. 51. Reyansh is working on a project where he needs to save the results of his experiments in a structured format. He decides to use a CSV file for this purpose. What does the csv.writer() function do? A) It converts CSV data to JSON format. B) It deletes data from a CSV file. C) It reads data from a CSV file. D) It writes data to a CSV file. Show Answer Correct Answer: D) It writes data to a CSV file. 52. ..... is the process of converting Python object hierarchy into a byte stream so that it can be written to a file A) Serialization. B) Conversion. C) Translation. D) Unpickling. Show Answer Correct Answer: A) Serialization. 53. Which method is used to list all files and directories in a directory in Python? A) Os.list(). B) Os.listdir(). C) Os.files(). D) Os.getdir(). Show Answer Correct Answer: B) Os.listdir(). 54. What is the key function for working with files in Python? A) Read(). B) File(). C) Close(). D) Open(). Show Answer Correct Answer: D) Open(). 55. Flush() is used to A) Transfer the contents from buffer to file. B) Its closes the file. C) Transfer the contents from buffer to file and closes the file. D) Erase the data from the file. Show Answer Correct Answer: A) Transfer the contents from buffer to file. 56. What is the Output of following program?#include int main(){ int x = 5; int * const ptr = &x; ++(*ptr); printf("%d", x); return 0; } A) 5. B) Runtime error. C) 6. D) Compiler error. Show Answer Correct Answer: C) 6. 57. If CSV contains values like "New, Delhi", how is it handled? A) Removed comma. B) Error occurs. C) Split into 2 fields. D) Enclosed in quotes. Show Answer Correct Answer: D) Enclosed in quotes. 58. The prefix r in front of a string makes it raw string that means ..... A) Special meaning to a number. B) No Special meaning to a number. C) No Special meaning to a character. D) Special meaning to a character. Show Answer Correct Answer: C) No Special meaning to a character. 59. What is the default mode in which a file is opened using open()? A) Read. B) Append. C) Write. D) Exclusive. Show Answer Correct Answer: A) Read. 60. ..... file is used to transfer data from one application to another A) Text. B) Binary. C) CSV. D) None. Show Answer Correct Answer: A) 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