Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q571: What happens if you use cin to read an integer and enter a non-numeric character?
- A: The program will execute normally
- B: An error will occur
- C: The input will be converted to zero
- D: The program will terminate
View Answer
B
Q572: Which of the following is true about the << operator used with cout?
- A: It inserts data into the output stream
- B: It extracts data from the input stream
- C: It performs mathematical operations
- D: It formats the input data
View Answer
A
Q573: How does the cerr stream differ from cout?
- A: cerr is buffered; cout is unbuffered
- B: cerr is unbuffered; cout is buffered
- C: Both are buffered
- D: Both are unbuffered
View Answer
B
Q574: What is the use of endl in C++ streams?
- A: It adds a new line to the output and flushes the buffer
- B: It adds a new line without flushing the buffer
- C: It terminates the program
- D: It clears the input buffer
View Answer
A
Q575: What does the getline function do in C++?
- A: Reads a single character from the input
- B: Reads a complete line up to a delimiter
- C: Reads data until the buffer is full
- D: Reads and formats data for output
View Answer
B
Q576: Which header file is needed for using manipulators in C++ streams?
- A: iostream.h
- B: fstream.h
- C: iomanip.h
- D: iostream.h and fstream.h
View Answer
C
Q577: What function checks if the end of a file has been reached in a stream?
- A: cin.fail()
- B: cin.bad()
- C: cin.eof()
- D: cin.clear()
View Answer
C
Q578: What does the function cin.clear() do?
- A: It checks the state of the end of file.
- B: It clears the error flags and sets the stream to good state.
- C: It checks for formatting errors.
- D: It sets the fail bit.
View Answer
B
Q579: Which manipulator is used to set the number of decimal places for floating-point numbers?
- A: setw()
- B: setfill()
- C: setprecision()
- D: endl()
View Answer
C
Q580: How can you print a number in hexadecimal format using manipulators?
- A: cout << hex << i
- B: cout << dec << i
- C: cout << setw(8) << i
- D: cout << setbase(10) << i
View Answer
A