Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q581: What does the setw manipulator do in C++?
- A: Sets the width of the field for the next output.
- B: Sets the precision of floating-point numbers.
- C: Sets the base for numeric conversion.
- D: Inserts a new line.
View Answer
A
Q582: How does setfill manipulator work with setw?
- A: It determines the width of the field.
- B: It fills empty spaces with a specified character.
- C: It sets the precision for floating-point numbers.
- D: It clears the error flags.
View Answer
B
Q583: What is the purpose of the showbase flag in C++ stream manipulations?
- A: To show the base of the number in the output.
- B: To set the width of the output field.
- C: To set the fill character for the output.
- D: To set the precision of floating-point numbers.
View Answer
A
Q584: Which manipulator skips whitespace characters in input?
- A: ws
- B: endl
- C: flush
- D: setfill
View Answer
A
Q585: What is the effect of using setprecision(2) with cout?
- A: It prints floating-point numbers with two decimal places.
- B: It sets the width of the output field to 2.
- C: It converts decimal numbers to hexadecimal format.
- D: It flushes the output buffer.
View Answer
A
Q586: What does cout << setbase(16) << i; do?
- A: Prints the integer i in hexadecimal format.
- B: Prints the integer i in decimal format.
- C: Prints the integer i in octal format.
- D: Sets the base of the stream to 10.
View Answer
A
Q587: Which function sets the width of the field for the next output?
- A: width()
- B: setprecision()
- C: setfill()
- D: setw()
View Answer
D
Q588: How are the effects of manipulators like setw and setprecision limited?
- A: They apply to all subsequent output operations.
- B: They apply only to the next output operation.
- C: They apply to all input operations.
- D: They apply only to the next input operation.
View Answer
B
Q589: What is the purpose of cout.fill('*')?
- A: To set the fill character to '*'.
- B: To set the width of the output field to 10.
- C: To set the precision of floating-point numbers.
- D: To insert a newline in the output.
View Answer
A
Q590: What is the purpose of overloading the stream insertion operator (<<) in C++?
- A: To change the behavior of input operations
- B: To change the behavior of output operations
- C: To add new operators to the language
- D: To modify the behavior of arithmetic operations
View Answer
B