Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Multiple Choice Questions

Q271: What is the function getline() used for in the code provided?
  • A: To write a line to the file
  • B: To read a line from the file
  • C: To open a file
  • D: To split a string into tokens
View Answer
B

Q272: What is the purpose of checking if (!inFile) in the provided program?
  • A: To ensure the file can be opened for reading
  • B: To write data to the file
  • C: To check if the file is empty
  • D: To convert file contents to integers
View Answer
A

Q273: In the given code, what will inFile.getline(completeLineText, MAX_CHAR_TO_READ); do?
  • A: It will write a line to the file
  • B: It will read a line from the file into the completeLineText array
  • C: It will close the file
  • D: It will open the file
View Answer
B

Q274: What will the output be when the input file contains Hello World and inFile.getLine(str, 20, ‘W’); is executed?
  • A: Hello World
  • B: Hello
  • C: World
  • D: ello
View Answer
B

Q275: What does the concept of sequential access in files imply?
  • A: Writing in a random manner
  • B: Writing and reading in a sequence
  • C: Reading from the end
  • D: Skipping unread data
View Answer
B

Q276: Which function is used to open a file in C++?
  • A: read()
  • B: open()
  • C: close()
  • D: write()
View Answer
B

Q277: What does the close() function do in file handling?
  • A: Opens a file
  • B: Closes a file
  • C: Reads a file
  • D: Writes to a file
View Answer
B

Q278: Which mode is used by default when opening a file for reading with ifstream?
  • A: ios::out
  • B: ios::in
  • C: ios::app
  • D: ios::trunc
View Answer
B

Q279: What is the default behavior of ofstream when opening a file for writing?
  • A: Appends data to the file
  • B: Deletes the previous contents of the file
  • C: Opens the file in read mode
  • D: Creates a new file if it doesn’t exist
View Answer
B

Q280: Which mode is used to append data to an existing file?
  • A: ios::trunc
  • B: ios::in
  • C: ios::out
  • D: ios::app
View Answer
D

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now