LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Exercise 1 of 4

Input/Output with cin and cout Input/Output MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ streams: cin and cout, manipulators, getline, stream states, string streams, std::format and fast I/O. Pick an option to check your answer instantly.

Question 1 Easy

What are std::cin and std::cout?

A Keywords of the C++ language
B Objects of type std::istream and std::ostream declared in <iostream>
C Functions like printf and scanf
D Macros defined by the compiler
Question page & discussion
Question 2 Easy

In std::cout << x, what is << called?

A Left shift only
B The insertion operator (an overloaded left-shift operator)
C The extraction operator
D The scope operator
Question page & discussion
Question 3 Medium

Why does std::cout << a << b; work?

A The compiler treats it specially
B operator&lt;&lt; returns a reference to the stream, so the result of the first call is the left operand of the next
C cout stores all values in an array
D It only works for two values
Question page & discussion
Question 4 Easy

What does std::cin >> x do with spaces and newlines before the value?

A Stores them in x
B Skips them
C Stops reading and fails
D Converts them to 0
Question page & discussion
Question 5 Easy

Which call reads a whole line such as Rahul Kumar Sharma into a std::string?

A std::cin &gt;&gt; name;
B std::getline(std::cin, name);
C std::cin.get(name);
D std::cin.read(name);
Question page & discussion
Question 6 Medium

After std::cin >> age;, the next std::getline(std::cin, name); returns an empty string. Why?

A getline is broken
B The newline typed after the age is still in the input buffer, and getline reads up to it immediately
C age must be a string
D getline needs a third argument
Question page & discussion
Question 7 Medium

What does std::cin >> std::ws do?

A Writes a space
B Extracts and discards all leading whitespace
C Sets the field width
D Waits for a key press
Question page & discussion
Question 8 Easy

Which header declares std::setw, std::setfill and std::setprecision?

A &lt;iostream&gt;
B &lt;iomanip&gt;
C &lt;format&gt;
D &lt;cstdio&gt;
Question page & discussion
Question 9 Medium

Which manipulator affects only the next value written?

A std::setprecision
B std::setw
C std::hex
D std::left
Question page & discussion
Question 10 Medium

With std::fixed set, what does std::setprecision(2) control?

A The total number of significant digits
B The number of digits after the decimal point
C The field width
D The number of digits before the decimal point
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links