250+ TOP MCQs on Input Stream and Answers

This section on C++ Programming quiz on “Input Stream”. One shall practice these quizzes to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ quiz comes with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ Programming quiz on “Input Stream” along with answers, explanations and/or solutions:

1. Which operator is used for input stream?
a) >
b) >>
c) <
d) <<
Answer: b
Clarification: The operator of extraction is >> and it is used on the standard input stream.

2. Where does a cin stops it extraction of data?
a) By seeing a blank space
b) By seeing (
c) By seeing a blank space & (
d) By seeing <
Answer: a
Clarification: cin will stop its extraction when it encounters a blank space.

3. Which is used to get the input during runtime?
a) cout
b) cin
c) coi
d) cinout
Answer: b
Clarification: cin is mainly used to get the input during the runtime.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int i;
  6.         cout << "Please enter an integer value: ";
  7.         cin >> i + 4;
  8.         return 0;
  9.     }

a) 73
b) your value + 4
c) Error
d) 63
Answer: c
Clarification: We are not allowed to do addition operation on cin.

5. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main ()
  6.     {
  7.         string mystr;
  8.         float price = 0;
  9.         int quantity = 0;
  10.         cout << "Enter price: ";
  11.         getline (cin, mystr);
  12.         stringstream(mystr) >> price;
  13.         cout << "Enter quantity: ";
  14.         getline (cin, mystr);
  15.         stringstream(mystr) >> quantity;
  16.         cout << "Total price: " << price * quantity << endl;
  17.         return 0;
  18.     }

a) 50
b) Depends on value you enter
c) Error
d) 100
Answer: b
Clarification: In this program, We are getting the input on runtime and manipulating the value.
Output:

$ g++ inp.cpp
$ a.out
Enter price: 3
Enter quantity: 4
Total price: 12

6. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     #include 
  5.     using namespace std;
  6.     template <typename CharT>
  7.     void ignore_line ( basic_istream<CharT>& in )
  8.     {
  9.         in.ignore ( numeric_limits<streamsize> :: max(), in.widen ( 'n' ) );
  10.     }
  11.     int main()
  12.     {
  13.         cout << "First input: ";
  14.         cin.get();
  15.         cout << "Clearing cin.n";
  16.         cin.clear();
  17.         ignore_line ( cin );
  18.         cout << "All done.n";
  19.     }

a) First input
b) Clearing cin
c) Error
d) Second input
Answer: d
Clarification: In this program, We are getting the input and clearing all the values.
Output:

$ g++ inp1.cpp
$ a.out
First input: 4
Clearing cin.
All done.

7. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main( )
  4.     {
  5.         char line[100];
  6.         cin.getline( line, 100, 't' );
  7.         cout << line;
  8.         return 0;
  9.     }

a) 100
b) t
c) It will print what we enter till character t is encountered in the input data
d) 200
Answer: c
Clarification: The program will store all strings entered and will print them only when the character ‘t’ is encountered.

Input >> coding
Input >> is fun
Input >> t

Output:
coding
is fun

8. How many parameters are there in getline function?
a) 1
b) 2
c) 2 or 3
d) 3
Answer: c
Clarification: There are two or three parameters in getline() function. They are a pointer to an array of characters and maximum number of characters and an optional delimiter.

9. What can be used to input a string with blank space?
a) inline
b) getline
c) putline
d) setline
Answer: b
Clarification: If a user wants to input a sentence with blank spaces, then he may use the function getline.

10. When will the cin can start processing of input?
a) After pressing return key
b) BY pressing blank space
c) After pressing return key & BY pressing blank space
d) BY pressing delete space
Answer: a
Clarification: When you give some input to console the processing of the input starts when the user presses enter/return key.

  250+ TOP MCQs on Overloaded Function Names and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top