Which of the following is the insertion operator in C++, used to write…
2018
Which of the following is the insertion operator in C++, used to write formatted data into the stream?
- A.
>>
- B.
<<
- C.
&&
- D.
<>
Attempted by 247 students.
Show answer & explanation
Correct answer: B
In C++, the insertion operator is represented by the double less-than symbol (<<). This operator is overloaded in the standard library to write formatted data into output streams, such as std::cout. When you use cout << variable_name, the compiler directs the value of variable_name to be inserted into the output stream for display. Option B correctly identifies this symbol as the insertion operator.\nOption A (>>) is incorrect because it represents the extraction operator, which reads data from an input stream like std::cin into a variable. Option C (&&) is the logical AND operator used for boolean logic, not stream manipulation. Option D (<>) is not a valid C++ operator; it resembles the less-than and greater-than symbols but does not function as an insertion or extraction mechanism. Therefore, understanding the direction of the arrows is key: << inserts data into a stream (left to right), while >> extracts data from a stream.