Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q261: How can you read multiple words from a file into different variables in C++?
- A: myFile << c1 << c2 << c3;
- B: myFile.read(c1, c2, c3);
- C: myFile >> c1 >> c2 >> c3;
- D: myFile.scanf(c1, c2, c3);
View Answer
C
Q262: What is the correct syntax to close a file in C++?
- A: myFile.close();
- B: close(myFile);
- C: fclose(myFile);
- D: file.close(myFile);
View Answer
A
Q263: Which function is used to check for the end of a file while reading in C++?
- A: myFile.end()
- B: myFile.eof()
- C: myFile.close()
- D: myFile.read()
View Answer
B
Q264: In the context of file handling, what does the term 'volatile' refer to?
- A: File data that is stored permanently
- B: File data that is temporarily stored in memory
- C: File data that can be executed as a program
- D: File data that can be shared over the network
View Answer
B
Q265: What is the purpose of the outFile.open(outputFileName, ios::out); statement in the provided code?
- A: To read data from the file
- B: To write data to the file
- C: To close the file
- D: To check if the file exists
View Answer
B
Q266: What does the outFile << ouputText; statement do in the code?
- A: It reads text from the file
- B: It writes text to the file
- C: It closes the file
- D: It opens the file
View Answer
B
Q267: What will happen if the file \"myFileOut.txt\" cannot be opened?
- A: The program will continue normally
- B: The program will display an error and exit
- C: The program will create a new file
- D: The program will write an error message to the file
View Answer
B
Q268: In the program to increase employee salaries, what does the strtok() function do?
- A: Reads the entire line as a string
- B: Splits the string into tokens based on the delimiter
- C: Converts a string to an integer
- D: Writes data to the file
View Answer
B
Q269: What is the purpose of the atoi(tokenPtr); function in the employee salary program?
- A: To convert an integer to a string
- B: To convert a string to an integer
- C: To read a line from the file
- D: To write a string to the file
View Answer
C
Q270: Why is it important to close a file after operations are done using close() function?
- A: To prevent memory leaks
- B: To ensure all data is written and resources are freed
- C: To open another file
- D: To convert file data to a string
View Answer
B