Paper Tayyari

Lecture 37: Overloading Insertion and Extraction Operators

MCQs, short and long questions from lecture 37.Lecture 37 ki MCQs, short aur long sawal.

7 MCQs · 3 short · 1 long question · 7 MCQs from past papers7 MCQs · 3 short · 1 long sawal · 7 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/7
– correctsahi
1.
★ Final term 2017 (paper 1)

The return type of the operator function for << operator is ________.

  1. Aclass for which we overload operator
  2. Breference of ostream class (ostream&)
  3. Creference of istream class (istream&)
  4. Dvoid

operator<< returns ostream& so that insertions can be chained.

2.
★ Final term 2017 (paper 1)

The stream insertion and stream extraction operators are already overloaded for ________.

  1. AUser-defined data types
  2. BBuilt-in data types
  3. CUser-defined and built-in data types
  4. DConstants

The library overloads << and >> for built-in types; user-defined types need their own overloads.

3.
★ Final term 2017 (paper 4)

The stream insertion and extraction operators ____________.

  1. Amust be overloaded as member function
  2. Bmust be overloaded as non-member function
  3. Ccan be overloaded either as member or non-member
  4. Dalways overloaded in class functions

The left operand is a stream object, not the user's class, so << and >> for a user class are overloaded as non-member (usually friend) functions.

4.
★ Final term solved MCQs (Moaaz & Asad)

The first parameter of operator function for << operator,

  1. AMust be passed by value
  2. BMust be passed by reference
  3. CCan be passed by value or reference
  4. DMust be object of class

The ostream argument cannot be copied, so it is taken by reference.

5.
★ Final term solved MCQs (Moaaz & Asad)

The second parameter of operator functions for << and >> are objects of the class for which we are overloading these operators.

  1. ATrue
  2. BFalse

The stream comes first and the class object second, e.g. ostream& operator<<(ostream&, const T&).

6.
★ Final term solved MCQs (Moaaz & Asad)

The first parameter of overloaded stream insertion operator is _________ where second parameter is _______

  1. Ainput stream, object of class
  2. Bobject of class, output stream
  3. Coutput stream, object of class
  4. Dobject of class, input stream

operator<< takes the ostream first and the class object second.

7.
★ Final term solved MCQs (Moaaz & Asad)

The operator function of << and >> operators are always the member function of a class.

  1. ATrue
  2. BFalse

Stream operators are normally non-member (often friend) functions since the stream is the left operand.