Skip to main content

Important Introduction to Programming Short Questions

Chapter: 18
Question 1:
What is the difference between ios::app and ios::ate modes?
Answer: ios::app appends data at the end of the file, while ios::ate allows writing data anywhere in the file without truncating it.
Chapter: 18
Question 2:
What function is used to read a character from a file in C++?
Answer: The get() function is used to read a single character from a file.
Chapter: 18
Question 3:
What function is used to write a single character to a file in C++?
Answer: The put() function is used to write a single character to a file.
Chapter: 18
Question 4:
How can you initialize a file stream variable when declaring it?
Answer: You can initialize a file stream variable directly using syntax like ifstream inFile("myFileIn.txt");.
Chapter: 18
Question 5:
What is the purpose of getLine() in file handling?
Answer: The getLine() function reads an entire line from the input file, up to a specified maximum number of characters.
Chapter: 18
Question 6:
How do you use strtok() to split a string in C++?
Answer: strtok() is used to tokenize a string by splitting it using a specified delimiter, like a space, returning each token sequentially.
Chapter: 18
Question 7:
How do you convert a string to an integer in C++?
Answer: You can convert a string to an integer using the atoi() function in C++.
Chapter: 18
Question 8:
What does ios::binary mode do when opening a file?
Answer: The ios::binary mode treats the file as binary, storing data in its internal format instead of readable text format.
Chapter: 18
Question 9:
How do you handle errors when opening a file in C++?
Answer: Errors are handled by checking the file stream (e.g., if (!inFile)) and displaying an error message or exiting the program.
Chapter: 18
Question 10:
What is the benefit of reading and writing data in chunks?
Answer: Reading and writing data in larger chunks (like 64k or 256k) improves efficiency by reducing the number of disk access operations.