Site icon T4Tutorials.com

Input and output (cin, cout, manipulators) — C++ MCQs

Q#1: Which header file is required for using cin and cout?
(A) <stdio.h>
(B) <iostream>
(C) <iomanip>
(D) <fstream>
Answer: (B) <iostream>

Q#2: Which operator is used for output in C++?
(A) >>
(B) <<
(C) +=
(D) =>
Answer: (B) <<

Q#3: Which operator is used for input in C++?
(A) >>
(B) <<
(C) =
(D) <=
Answer: (A) >>

Q#4: Which of the following is a manipulator used to set the width of output?
(A) endl
(B) setw
(C) setprecision
(D) fixed
Answer: (B) setw

Q#5: Which manipulator is used to insert a newline in output?
(A) endl
(B) setw
(C) setprecision
(D) fixed
Answer: (A) endl

Q#6: What will cout << 5 << 10; output?
(A) 5 10
(B) 510
(C) 15
(D) Error
Answer: (B) 510

Q#7: Which header file is required for manipulators like setw and setprecision?
(A) <iostream>
(B) <iomanip>
(C) <fstream>
(D) <cstdio>
Answer: (B) <iomanip>

Q#8: What does setprecision(3) do?
(A) Sets width of output to 3
(B) Displays floating-point numbers with 3 digits after decimal
(C) Rounds integer values to nearest 3
(D) Limits input to 3 characters
Answer: (B) Displays floating-point numbers with 3 digits after decimal

Q#9: Which of the following statements is correct?
(A) cin can read multiple values at once
(B) cout can print multiple values at once
(C) Both A and B
(D) Neither A nor B
Answer: (C) Both A and B

Q#10: What is the effect of fixed manipulator in C++?
(A) Displays integer values only
(B) Formats floating-point output in fixed-point notation
(C) Inserts a fixed number of spaces
(D) Stops program execution
Answer: (B) Formats floating-point output in fixed-point notation

Exit mobile version