Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q311: Which stream class can be used for both input and output operations in C++?
  • A: ifstream
  • B: ofstream
  • C: fstream
  • D: file_stream
View Answer
C

Q312: When replacing a character in a sentence within a file, what function can be used to move the file pointer to a specific position?
  • A: seekg()
  • B: seekp()
  • C: tellg()
  • D: tellp()
View Answer
B

Q313: How does the tellg() function help in file operations?
  • A: It opens the file
  • B: It writes data to the file
  • C: It returns the current position of the file pointer
  • D: It moves the file pointer to a specific location
View Answer
C

Q314: What is the impact of using constant record lengths in files?
  • A: Ensures efficient string comparison
  • B: Allows updating data without disturbing the file structure
  • C: It increases file size
  • D: It makes the file access slower
View Answer
B

Q315: Why is it not practical to insert data in the middle of a sequential file without additional techniques?
  • A: It can corrupt the file
  • B: It requires complex algorithms
  • C: Disk space needs to be reorganized
  • D: It requires specialized hardware
View Answer
C

Q316: What is the function of the seekg() function in file handling?
  • A: It reads data from a file.
  • B: It writes data to a file.
  • C: It moves the file pointer to a specific location.
  • D: It closes the file.
View Answer
C

Q317: In the code aFile.seekg(-1L, ios::end);, what does -1L signify?
  • A: Move the file pointer forward by one byte.
  • B: Move the file pointer backward by one byte from the end of the file.
  • C: Move the file pointer to the beginning of the file.
  • D: Move the file pointer to the end of the file.
View Answer
B

Q318: What happens when you attempt to move the file pointer before the beginning of a file?
  • A: The file pointer wraps around to the end of the file.
  • B: An error occurs.
  • C: The file pointer remains at the beginning of the file.
  • D: The file pointer moves to the middle of the file.
View Answer
B

Q319: What is the advantage of using the sizeof() function while writing an integer to a file?
  • A: It avoids magic numbers and ensures portability across different systems.
  • B: It speeds up the file writing process.
  • C: It reduces the file size.
  • D: It ensures the file is written in text format.
View Answer
A

Q320: In the program that writes integers from 0 to 99 into a file using the write() function, what type of write operation is performed?
  • A: Text write
  • B: Binary write
  • C: ASCII write
  • D: Hexadecimal write
View Answer
B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now