Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q281: What will ios::ate do when used while opening a file?
- A: Opens the file and positions at the start
- B: Opens the file and positions at the end
- C: Appends the file
- D: Opens the file and truncates its contents
View Answer
B
Q282: Which function is used to read a character from a file character by character?
- A: get()
- B: put()
- C: read()
- D: write()
View Answer
A
Q283: How does the getline() function treat the lines read from a file?
- A: As a number
- B: As a character array
- C: As a character string
- D: As a stream
View Answer
C
Q284: What does tellg() function return?
- A: Current read position in the file
- B: Current write position in the file
- C: File length
- D: Pointer to the start of the file
View Answer
A
Q285: Which function is used to determine the current write position in a file?
- A: tellg()
- B: tellp()
- C: seekg()
- D: seekp()
View Answer
B
Q286: What does the seekg() function do?
- A: Moves file pointer to the start of the file
- B: Moves file pointer to the end of the file
- C: Moves file pointer to a specific position
- D: Moves file pointer to the next line
View Answer
C
Q287: Which argument type is required by the seekg() and seekp() functions to move the file pointer?
- A: int
- B: float
- C: double
- D: long
View Answer
D
Q288: How can you move 10 bytes forward from the beginning of a file?
- A: aFile.seekg(10L, ios::beg)
- B: aFile.seekg(-10L, ios::beg)
- C: aFile.seekg(10L, ios::end)
- D: aFile.seekg(-10L, ios::end)
View Answer
A
Q289: How can you move 20 bytes forward from the current position in a file?
- A: aFile.seekg(20L, ios::beg)
- B: aFile.seekg(20L, ios::cur)
- C: aFile.seekg(20L, ios::end)
- D: aFile.seekg(-20L, ios::end)
View Answer
B
Q290: How can you move the file pointer 10 bytes backward from the current position?
- A: aFile.seekg(10L, ios::beg)
- B: aFile.seekg(10L, ios::cur)
- C: aFile.seekg(-10L, ios::cur)
- D: aFile.seekg(-10L, ios::end)
View Answer
C