Q1. File handling allows a program to AOnly print on screenBOnly perform calculationsCStore and retrieve data permanentlyDOnly use RAM Show answer Answer: C. Store and retrieve data permanently Report a mistake
Q2. The header file required for file handling in C++ is A<fstream>B<iostream>C<stdio.h> onlyD<file.h> Show answer Answer: A. <fstream> Report a mistake
Q3. ifstream is used for ABoth reading and writingBWriting to a fileCReading from a fileDCreating directories Show answer Answer: C. Reading from a file Report a mistake
Q4. ofstream is used for AWriting to a fileBBothCReading from a fileDDeleting files Show answer Answer: A. Writing to a file Report a mistake
Q5. fstream can be used for AOnly readingBBoth reading and writingCOnly appendingDOnly writing Show answer Answer: B. Both reading and writing Report a mistake
Q6. To open a file we use AOnly fopen in C styleBOnly newCOnly create()Dopen() member function or constructor Show answer Answer: D. open() member function or constructor Report a mistake
Q7. The mode ios::in is used for AOutput (writing)BAppendCInput (reading)DBinary Show answer Answer: C. Input (reading) Report a mistake
Q8. The mode ios::out is used for AAppend onlyBInputCOutput (writing)DBinary only Show answer Answer: C. Output (writing) Report a mistake
Q9. The mode ios::app is used for AOverwrite the fileBRead onlyCCreate new file onlyDAppend data at the end of file Show answer Answer: D. Append data at the end of file Report a mistake
Q10. The mode ios::binary is used for AOnly reading textBText file onlyCBinary file operationsDOnly writing text Show answer Answer: C. Binary file operations Report a mistake
Q11. The mode ios::trunc AAppends dataBCreates a backupCTruncates (empties) the file if it already existsDOpens for reading only Show answer Answer: C. Truncates (empties) the file if it already exists Report a mistake
Q12. To check whether a file is opened successfully we use AOnly bad()Bis_open() or fail()COnly good()DOnly eof() Show answer Answer: B. is_open() or fail() Report a mistake
Q13. eof() returns true when AFile is closedBFile is openedCError occursDEnd of file is reached Show answer Answer: D. End of file is reached Report a mistake
Q14. The statement file.close(); is used to AClose the fileBDelete the fileCClear the fileDOpen the file Show answer Answer: A. Close the file Report a mistake
Q15. Text files store data in AHuman-readable form (ASCII/Unicode)BEncrypted form onlyCBinary form onlyDCompressed form only Show answer Answer: A. Human-readable form (ASCII/Unicode) Report a mistake
Q16. Binary files store data in ASame format as it is stored in memoryBOnly numbersCAlways text formatDAlways encrypted Show answer Answer: A. Same format as it is stored in memory Report a mistake
Q17. put() function is used to ARead a lineBRead a single characterCWrite a single character to a fileDWrite a string Show answer Answer: C. Write a single character to a file Report a mistake
Q18. get() function is used to AWrite a stringBRead a single character from a fileCRead an integerDWrite a single character Show answer Answer: B. Read a single character from a file Report a mistake
Q19. getline() is used to AWrite a lineBWrite a characterCRead a single characterDRead a complete line from a file Show answer Answer: D. Read a complete line from a file Report a mistake
Q20. write() function is used for AReading text onlyBReading data in binary formCWriting text onlyDWriting data in binary form Show answer Answer: D. Writing data in binary form Report a mistake
Q21. read() function is used for AReading text onlyBWriting data in binary formCWriting text onlyDReading data in binary form Show answer Answer: D. Reading data in binary form Report a mistake
Q22. seekg() is used to AMove the put pointerBMove the get pointer (for reading)CClose the fileDOpen the file Show answer Answer: B. Move the get pointer (for reading) Report a mistake
Q23. seekp() is used to AMove the get pointerBMove the put pointer (for writing)CRead dataDWrite data Show answer Answer: B. Move the put pointer (for writing) Report a mistake
Q24. tellg() returns ASize of file onlyBCurrent position of get pointerCNumber of recordsDCurrent position of put pointer Show answer Answer: B. Current position of get pointer Report a mistake
Q25. tellp() returns ACurrent position of put pointerBBeginning of fileCCurrent position of get pointerDEnd of file Show answer Answer: A. Current position of put pointer Report a mistake
Q26. ios::beg means AEnd of the fileBCurrent positionCBeginning of the fileDMiddle of file Show answer Answer: C. Beginning of the file Report a mistake
Q27. ios::end means ARandom positionBBeginning of the fileCCurrent positionDEnd of the file Show answer Answer: D. End of the file Report a mistake
Q28. ios::cur means AEndBBeginningCCurrent position of the pointerDFixed position Show answer Answer: C. Current position of the pointer Report a mistake
Q29. Sequential access means AReading/writing data in order from start to endBJumping to any position directlyCOnly writingDOnly reading Show answer Answer: A. Reading/writing data in order from start to end Report a mistake
Q30. Random access means AOnly sequential readingBOnly appendingCOnly creating new fileDAbility to move to any position in the file Show answer Answer: D. Ability to move to any position in the file Report a mistake
Q31. File pointer is AAn indicator of current position in the fileBA functionCA normal C++ pointerDA class Show answer Answer: A. An indicator of current position in the file Report a mistake
Q32. When a file is opened in ios::out mode and file already exists AIts contents are discarded (truncated)BData is appendedCError occurs alwaysDFile is deleted permanently Show answer Answer: A. Its contents are discarded (truncated) Report a mistake
Q33. To open a file for both reading and writing we use AOnly ios::appBfstream with ios::in | ios::outCOnly ofstreamDOnly ifstream Show answer Answer: B. fstream with ios::in | ios::out Report a mistake
Q34. The default open mode for ofstream is Aios::outBios::inCios::appDios::binary Show answer Answer: A. ios::out Report a mistake
Q35. The default open mode for ifstream is Aios::inBios::truncCios::appDios::out Show answer Answer: A. ios::in Report a mistake
Q36. fail() returns true when AEnd of file is reachedBData is writtenCAn operation fails (e.g., file not found)DFile is successfully opened Show answer Answer: C. An operation fails (e.g., file not found) Report a mistake
Q37. bad() returns true when ASuccessful operationBA serious error occurs (e.g., hardware failure)CEnd of fileDFile is closed Show answer Answer: B. A serious error occurs (e.g., hardware failure) Report a mistake
Q38. good() returns true when ANo error has occurredBFile cannot be openedCEnd of file is reachedDSerious error Show answer Answer: A. No error has occurred Report a mistake
Q39. clear() function is used to AClose the fileBDelete the fileCClear error flags of the streamDClear the contents of file Show answer Answer: C. Clear error flags of the stream Report a mistake
Q40. File handling is necessary because AFiles are slower alwaysBRAM is permanentCData in RAM is temporary (lost when program ends)DNo need for permanent storage Show answer Answer: C. Data in RAM is temporary (lost when program ends) Report a mistake
Q41. A record in a file usually consists of ARandom dataBOnly one characterCRelated fields of dataDOnly one integer Show answer Answer: C. Related fields of data Report a mistake
Q42. To write an object to a binary file we use AOnly getline()BOnly put()Cwrite((char*)&object, sizeof(object))DOnly << operator Show answer Answer: C. write((char*)&object, sizeof(object)) Report a mistake
Q43. To read an object from a binary file we use Aread((char*)&object, sizeof(object))BOnly get()COnly getline()DOnly >> operator Show answer Answer: A. read((char*)&object, sizeof(object)) Report a mistake
Q44. Opening a non-existent file in ios::in mode AAppends dataBCreates a new empty fileCDeletes other filesDCauses open to fail Show answer Answer: D. Causes open to fail Report a mistake
Q45. Opening a non-existent file in ios::out mode AOpens existing file onlyBCreates a new empty fileCAppends to another fileDCauses error always Show answer Answer: B. Creates a new empty file Report a mistake
Q46. The stream hierarchy in C++ includes AOnly fstreamBOnly iostreamCOnly FILE*Dios → istream/ostream → ifstream/ofstream/fstream Show answer Answer: D. ios → istream/ostream → ifstream/ofstream/fstream Report a mistake
Q47. Closing a file is important because AIt deletes the fileBIt flushes buffers and releases resourcesCIt only works for text filesDIt is optional and never needed Show answer Answer: B. It flushes buffers and releases resources Report a mistake
Q48. Multiple files can be opened AOnly in main()BNeverCSimultaneously using different stream objectsDOnly one at a time in whole program Show answer Answer: C. Simultaneously using different stream objects Report a mistake
Q49. File handling errors should be AOnly checked at the endBIgnoredCAlways checked (is_open, fail, etc.)DOnly for binary files Show answer Answer: C. Always checked (is_open, fail, etc.) Report a mistake
Q50. The most common use of file handling is APermanent storage and retrieval of dataBOnly screen outputCOnly temporary calculationsDOnly memory allocation Show answer Answer: A. Permanent storage and retrieval of data Report a mistake