Skip to main content

Important Introduction to Programming Short Questions

Chapter: 18
Question 1:
How is file handling related to data volatility in computer memory?
Answer: File handling is crucial because data in computer memory is volatile and is lost when the computer is turned off. Files allow data to be saved permanently on disk.
Chapter: 18
Question 2:
What are the basic steps involved in file handling?
Answer: The basic steps in file handling are opening the file, reading or writing to the file, and closing the file.
Chapter: 18
Question 3:
What are 'cin' and 'cout' in C++?
Answer: 'cin' and 'cout' are streams in C++ used for input and output, respectively. They allow data to enter and exit a program.
Chapter: 18
Question 4:
Which header file is necessary for file handling in C++?
Answer: The header file necessary for file handling in C++ is <fstream.h>.
Chapter: 18
Question 5:
What are the three types of file streams in C++?
Answer: The three types of file streams in C++ are ifstream (input file stream), ofstream (output file stream), and fstream (for both input and output).
Chapter: 18
Question 6:
How do you declare an input file stream in C++?
Answer: An input file stream in C++ is declared as ifstream inFile;, where inFile is the handle to refer to the file.
Chapter: 18
Question 7:
What is the purpose of the open function in file handling?
Answer: The open function is used to associate a file with a file stream variable, allowing the file to be accessed for reading or writing.
Chapter: 18
Question 8:
How do you open a file using a fully qualified path in C++?
Answer: To open a file using a fully qualified path, you would use myFile.open("C:\\myprogs\\payroll.txt"); where myFile is the file stream object.
Chapter: 18
Question 9:
What happens if you try to read from a file using ifstream in C++?
Answer: If you try to read from a file using ifstream, the file is opened for input, and data can be read into variables using the extraction operator (>>).
Chapter: 18
Question 10:
How do you close a file in C++?
Answer: You close a file in C++ by calling the close() function, e.g., myFile.close();, where myFile is the file stream object.