Skip to main content

Important Introduction to Programming Short Questions

Chapter: 18
Question 1:
How can you append text to the end of an existing file?
Answer: Text can be appended to the end of an existing file by opening it in ios::app mode.
Chapter: 19
Question 2:
What does sequential access mean in file handling?
Answer: Sequential access means reading or writing a file in a specific order, from beginning to end, rather than accessing random positions.
Chapter: 19
Question 3:
What function is used to open a file in C++?
Answer: The open() function is used to open a file. It requires the filename and mode as parameters.
Chapter: 19
Question 4:
How do you open a file for reading using ifstream?
Answer: You can open a file for reading using ifstream by providing the filename, as ifstream file("filename").
Chapter: 19
Question 5:
What is the purpose of ios::app mode when opening a file for writing?
Answer: The ios::app mode opens a file for writing in append mode, so new data is added to the end without altering existing contents.
Chapter: 19
Question 6:
How can you avoid overwriting existing file content when opening for writing?
Answer: Use ios::app mode to append new data rather than overwriting the existing content.
Chapter: 19
Question 7:
What does seekg() function do?
Answer: The seekg() function sets the position of the get pointer (reading position) in a file stream.
Chapter: 19
Question 8:
What is the role of tellg() function?
Answer: The tellg() function returns the current position of the get pointer (reading position) in a file stream.
Chapter: 19
Question 9:
How would you move the file pointer to the 50th byte from the beginning using seekg()?
Answer: Use seekg(50L, ios::beg) to move the pointer to the 50th byte from the beginning of the file.
Chapter: 19
Question 10:
How can you determine the length of a file in C++?
Answer: Open the file, use seekg(0, ios::end) to move to the end, and then use tellg() to get the file size.