Skip to main content

Important Introduction to Programming Short Questions

Chapter: 19
Question 1:
What function is used to read an entire line from a file?
Answer: The getline() function reads an entire line from a file, including specifying the number of characters and delimiter.
Chapter: 19
Question 2:
What happens when you attempt to write beyond the end of a file using seekp()?
Answer: The file is extended with null characters to accommodate the new data if writing beyond the end.
Chapter: 19
Question 3:
How do you move the file pointer 20 bytes backward from the current position using seekg()?
Answer: Use seekg(-20L, ios::cur) to move the pointer 20 bytes backward from the current position.
Chapter: 19
Question 4:
What is the default mode of ofstream when opening a file?
Answer: The default mode of ofstream is to open a file for writing and truncate (overwrite) the existing content.
Chapter: 19
Question 5:
Why is it not efficient to copy a file one character at a time?
Answer: Copying one character at a time is inefficient due to excessive disk I/O operations and processing time.
Chapter: 19
Question 6:
How can you use seekg() and tellg() to determine the length of a file?
Answer: Move to the end of the file using seekg(0, ios::end) and use tellg() to get the file length.
Chapter: 19
Question 7:
What is the purpose of the ios::trunc mode when opening a file?
Answer: ios::trunc mode truncates the file to zero length, removing all existing content when opening for writing.
Chapter: 19
Question 8:
How do you append data to a file without overwriting existing data?
Answer: Open the file using ios::app mode to append data without overwriting the existing content.
Chapter: 19
Question 9:
What does the seekp() function do?
Answer: The seekp() function sets the position of the put pointer (writing position) in a file stream.
Chapter: 19
Question 10:
How do you move the file pointer to 100 bytes from the end using seekg()?
Answer: Use seekg(-100L, ios::end) to move the pointer 100 bytes backward from the end of the file.