Class 12 Computer Science Important Questions (ASSEB / AHSEC)

Chapter 6 - Data File Handling

1. What is Data File Handling?

Answer : File handling is a process that allows a C++ program to store data permanently in a file and retrieve it later when needed. Unlike RAM where data is stored temporarily, data stored in files remain available even after a program terminates or the computer is switched off

2. Why do we need Data File Handling?

Answer :Data File Handling is needed because without files:

  • Data is lost after program execution.
  • Records cannot be reused.

3. What are the types of data files?

Answer : 

  • Text files
  • Binary files

4. What are text files?

Answer : Data is stored in the form of characters

5. What are binary files?

Answer : Data is stored in the form of bytes (0 and 1).

6. Write the difference between text file and binary files?

Answer :
Text file Binary file
Text file data is stored in the form of characters Binary file data is stored in the form of bytes (0 and 1).
Human-readable Not human readable

7. What are the file stream classes?

Answer : 

  • ifstream
  • ofstream
  • fstream

8. Which header file is used for file handling?

Answer :

<fstream.h>

9. What are the 2 methods of opening a file?

Answer : 

1.using constructor

2. using open function

10. What are the different file opening modes?

Answer : 

  • ios::in
  • ios::out
  • ios::ate
  • ios::binary
  • ios::trunc

11. How do we detect end of a file?

Answer : When the end of a file is reached , the stream returns a special value called EOF (End of File)

Methods to detect end of file

1.fin.eof( ) : Returns true if end of file is reached

2.fin.fail( ) : Returns true if any input operation fails (including EOF).

12. Name some common functions used for file handling.

Answer :

1.get(char & ) – reads one character from file

2.put(char) – writes one character into file

3.getline( ) – reads a line from file (upto newline)

4.read(char*,n) – reads n bytes from binary file

5.write(char*,n) – writes n bytes into binary file

13. What do you mean by random access in files?

Answer :

Random access means accessing any record directly without reading all previous records. We can move the read/write pointer to any position in a file using the following functions:

1.seekg(pos)

2.seekp(pos)

3.tellg()

4.tellp() 

14. Define: seekg( ), seekp( ), tellg( ) and tellp( ).

Answer:

1.seekg(pos): moves the get pointer to pos position

2.seekp(pos):moves the put ponter to pos position

3.tellg():Returns current position of get pointer

4.tellp():Returns current position of put pointer

15. What are the functions used with binary files?

Answer : 

  • read( )
  • write( )
Scroll to Top