1.
Using friend operator function, following perfect set of operators may not be overloaded.
(a) = , ( ) , [ ] , ->
(b) <<, = = , [ ] , >>
(c) ?, = , ( ) , ++
(d) None of these
2.
An operator function is created using _____________ keyword.
(a) iterator
(b) allocator
(c) constructor
(d) operator
General form of a member operator function is as follows.
ret-type class-name::operator operator Sign (arg-list)
{
// operations
}
3.
While overloading binary operators using member function, it requires ___ arguments.
(a) Zero
(b) One
(c) Two
(d) Three
contains value of the object, which is to the right of the operator.
4.
In case of operator overloading, operator function must be ______ .
1. Static member functions
2. Non- static member functions
3. Friend Functions
(a) Only 2
(b) Only 1, 3
(c) Only 2 , 3
(d) All 1 , 2, 3
5.
When overloading unary operators using Friend function, it requires_____ argument/s.
(a) Zero
(b) One
(c) Two
(d) None of these.
6.
Which of the following operators cannot be overloaded.
(a) . (Member Access or Dot operator)
(b) ?: (Ternary or Conditional Operator
(c):: (Scope Resolution Operator)
(d) All of the above
7.
Which of the following operators should be preferred to overload as a global function rather than a member method?
(a) Postfix ++
(b) Comparison Operator
(c) Insertion Operator <<
(d) Prefix++
8.
Find the output of the Following:
using namespace std;
class Point {
private:
int x, y;
public:
Point() : x(0), y(0) { }
Point& operator()(int dx, int dy);
void show() {cout << “x = ” << x << “, y = ” << y; }
};
Point& Point::operator()(int dx, int dy)
{
x = dx;
y = dy;
return *this;
}
int main()
{
Point pt;
pt(3, 2);
pt.show();
return 0;
}
(a) x = 3, y = 2
(b) Compiler Error
(c) x = 2, y = 3
(d) None of these.
9.
How C++ compiler does differ between overloaded postfix and prefix operators?
(a) C++ doesn’t allow both operators to be overloaded in a class
(b) A postfix ++ has a dummy parameter
(c) A prefix ++ has a dummy parameter
(d) By making prefix ++ as a global function and postfix as a member function.
10.
How can we restrict dynamic allocation of objects of a class using new?
(a) By overloading new operator
(b) By making an empty private new operator.
(c) By making an empty private new and new[] operators
(d) By overloading new operator and new[] operators