Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Chapter: 19
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
Correct Answer: B
Chapter: 19
Q282:
Which function is used to read a character from a file character by character?
A. get()
B. put()
C. read()
D. write()
Correct Answer: A
Chapter: 19
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
Correct Answer: C
Chapter: 19
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
Correct Answer: A
Chapter: 19
Q285:
Which function is used to determine the current write position in a file?
A. tellg()
B. tellp()
C. seekg()
D. seekp()
Correct Answer: B
Chapter: 19
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
Correct Answer: C
Chapter: 19
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
Correct Answer: D
Chapter: 19
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)
Correct Answer: A
Chapter: 19
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)
Correct Answer: B
Chapter: 19
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)
Correct Answer: C
Chapter: 19
Q291:
What is the function of tellg() in relation to file length?
A. Determines the file's total size
B. Determines the position of the next character to be read
C. Determines the size of the string inside the file
D. Determines the position of the last character in the file
Correct Answer: B
Chapter: 19
Q292:
Which functions are used to determine the current position of the file pointer?
A. strlen() and seekg()
B. strlen() and seekp()
C. tellg() and tellp()
D. tellg() and seekg()
Correct Answer: C
Chapter: 19
Q293:
What is the purpose of seekp() in file handling?
A. Move the file pointer forward by one byte
B. Move the file pointer to a specific position for writing
C. Move the file pointer to the end of the file
D. Move the file pointer to the beginning of the file
Correct Answer: B
Chapter: 19
Q294:
What does ios::end indicate when used in file handling?
A. Beginning of the file
B. Current position in the file
C. End of the file
D. Middle of the file
Correct Answer: C
Chapter: 19
Q295:
How can you determine the length of a file using tellg() and seekg()?
A. Move to the end of the file with seekg() and use tellg
B. Count the characters one by one using tellg()
C. Use tellp() to calculate the length
D. Move to the start of the file with seekg() and use tellg
Correct Answer: A
Chapter: 19
Q296:
What is the minimum size of data that can be read from or written to a disk?
A. 1 byte
B. 53 bytes
C. 1 block
D. 1024 bytes
Correct Answer: C
Chapter: 19
Q297:
What function is used to determine the actual length of data in a file?
A. seekp()
B. tellp()
C. seekg()
D. tellg()
Correct Answer: D
Chapter: 19
Q298:
Which function is used to move the file pointer to the end of the file?
A. seekg(0, ios::beg)
B. seekg(0, ios::end)
C. tellg()
D. seekp(0, ios::end)
Correct Answer: B
Chapter: 19
Q299:
Why is seekg() used before performing operations on a file?
A. To find the start of the file
B. To find the end of the file
C. To find a specific location in the file
D. To calculate the file size
Correct Answer: C
Chapter: 19
Q300:
What is a potential issue when updating data in the middle of a file?
A. The file structure may get corrupted
B. Data may be lost
C. The disk may get damaged
D. The file will get locked
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now