This quiz works best with JavaScript enabled. Home > Class 11 > Class 11 Computer Science Chapter 6 File Handling – Quiz 42 🏠 Homepage 📘 Download PDF Books 📕 Premium PDF Books Class 11 Computer Science Chapter 6 File Handling Quiz 42 (25 MCQs) Quiz Instructions Select an option to see the correct answer instantly. 1. Which operator is used to write data to a file in C++? A) >>. B) > operator. C) Using 'ifstream' with 'getline()'. D) None of the above. Show Answer Correct Answer: C) Using 'ifstream' with 'getline()'. 2. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1) #include union uTemp \{ double a; int b[10]; char c; \}u; A) 4. B) 8. C) 40. D) 80. Show Answer Correct Answer: C) 40. 3. Str = "CBSE Class XII Python Examination 2024"Filein = open("myfile.txt", "w+")print("Name of the file: ", Filein.name)Filein.writelines(Str)Filein.seek(0, 0)for line in Filein:print(line)Filein.close() A) CBSE Class XII python Examination 2024. B) CBSE Class XII Python Examination 2024. C) Name of the file:myfile.txtCBSE Class XII Python Examination 2024. D) None. Show Answer Correct Answer: C) Name of the file:myfile.txtCBSE Class XII Python Examination 2024. 4. Why do we save files? A) To keep data temporarily. B) To keep data permanently. C) To store large data. D) To create digital documents. Show Answer Correct Answer: B) To keep data permanently. 5. What is the return type of the length() method in the File class? A) Float. B) Int. C) Long. D) Double. Show Answer Correct Answer: C) Long. 6. What is a file in the context of data storage? A) A collection of unrelated data. B) A type of software application. C) A hardware component of a computer. D) A collection of related data stored in a particular area on the disk. Show Answer Correct Answer: D) A collection of related data stored in a particular area on the disk. 7. When opening a file for writing using OPENFILE "data.txt" FOR WRITE, what happens if "data.txt" already exists? A) The file is deleted and a new empty file is created. B) The file cannot be opened unless it is empty. C) Data will be appended to the existing data. D) The file is opened normally with no changes to existing data. Show Answer Correct Answer: A) The file is deleted and a new empty file is created. 8. Files don't need to be closed when using file handling in programming A) True. B) False. C) All the above. D) None of the above. Show Answer Correct Answer: B) False. 9. Write the output of the following:>>> f = open("test.txt", "w") >>> f.closed >>> f.close() >>> f.closed A) False True. B) True False. C) Yes No. D) No Yes. Show Answer Correct Answer: A) False True. 10. What is the purpose of the 'seek' method in Python file handling? A) To move the file pointer to a specific position within the file. B) To close the file after reading or writing. C) To read the entire contents of the file. D) To delete the file from the system. Show Answer Correct Answer: A) To move the file pointer to a specific position within the file. 11. An interrupt or forced disruption that occurs when a program is run or executed is termed as A) Compile time error. B) Exception. C) Runtime error. D) Logical error. Show Answer Correct Answer: B) Exception. 12. What is the output of this program? #include int main()\{typedef struct tag \{char str[10];int a;\} tag;tag h1, h2 = \{ "IHelp", 10 \};h1 = h2;h1.str[1] = 'h';printf("%s, %d", h1.str, h1.a);return 0;\} A) Error. B) IHelp 10. C) Ihelp 10. D) No Error, No output. Show Answer Correct Answer: C) Ihelp 10. 13. What is the primary function of fopen() in C programming? A) To open a file for reading. B) To allocate memory dynamically. C) To close a file. D) To delete a file. Show Answer Correct Answer: A) To open a file for reading. 14. Which mode should you use to write a binary file? A) W. B) A. C) Wb. D) R. Show Answer Correct Answer: C) Wb. 15. What will malloc() return if it fails to allocate memory? A) NULL. B) -1. C) 0. D) 1. Show Answer Correct Answer: A) NULL. 16. Sizeof(struct) gives: A) Only sum of all fields. B) Always equal to sum. C) May be bigger due to padding. D) Always 4 bytes. Show Answer Correct Answer: C) May be bigger due to padding. 17. What is one way to avoid accidental changes to a file? A) Open the file in write mode. B) Open the file in read mode. C) Open the file in edit mode. D) Open the file in delete mode. Show Answer Correct Answer: B) Open the file in read mode. 18. Which function is used to open a file in Python? A) Open file(). B) Open(). C) File open(). D) Fopen(). Show Answer Correct Answer: B) Open(). 19. Which is more secure for sensitive data? A) Text File. B) Binary File. C) CSV File. D) None of these. Show Answer Correct Answer: B) Binary File. 20. Explain the process of reading a file line by line in Python. A) Open('file.txt', 'r').readlines():. B) With open('file.txt', 'r') as file:for line in file:print(line). C) File.read():. D) For line in file.readlines():. Show Answer Correct Answer: B) With open('file.txt', 'r') as file:for line in file:print(line). 21. Fp.readlines() returns data as a A) Tuple. B) List. C) Dictionary. D) String. Show Answer Correct Answer: B) List. 22. What does the function fgets do in file handling? A) Writes a string of text to a file. B) Closes an open file. C) Reads characters from a file and puts them in a buffer. D) Checks if the file has reached the end. Show Answer Correct Answer: C) Reads characters from a file and puts them in a buffer. 23. What does the abs() function in Python do? A) Converts a value to an absolute integer. B) Returns the absolute value of a number. C) Calculates the average of a sequence of numbers. D) Returns the absolute difference between two numbers. Show Answer Correct Answer: B) Returns the absolute value of a number. 24. What is the purpose of defining a function in Python? A) To create a new data type in Python. B) To increase the execution speed of the program. C) To encapsulate reusable code and improve organization. D) To define global variables for the entire program. Show Answer Correct Answer: C) To encapsulate reusable code and improve organization. 25. What is the prerequisite knowledge before learning file handling? A) Experience with databases. B) Basic knowledge of algorithms and variables. C) Understanding of file systems. D) Knowledge of network protocols. Show Answer Correct Answer: B) Basic knowledge of algorithms and variables. ← PreviousNext →Related 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 8Class 11 Computer Science Chapter 6 File Handling Quiz 9Class 11 Computer Science Chapter 6 File Handling Quiz 10 🏠 Back to Homepage 📘 Download PDF Books 📕 Premium PDF Books