Operators in C++ MCQs Exercise II

Ques 1 Operators


Which of the following operators can be overloaded globally, but not as class members?

A Assignment (=)
B Subscript ([])
C Stream insertion (<<)
D Function call (())

Ques 2 Operators


What will be the output of the following code?

#include<iostream>
using namespace std;
int main() {
    int x = 7, y = 3, z = 2;
    int res = x > y && y++ > z || ++z < x;
    cout << y << " " << z << " " << res;
    return 0;
}

A 3 3 1
B 4 2 1
C 4 3 1
D 3 2 0

Ques 3 Operators


What will be the output of the following code?

#include<iostream>
using namespace std;
int main() {
    int a = 5, b = 5;
    cout << (a++ == b--) << " " << a << " " << b;
    return 0;
}

A 0 6 4
B 1 6 4
C 0 5 5
D 1 5 5

Ques 4 Operators


Which of the following is the correct way to declare a friend function for overloading an operator in C++?

A friend operator+(const A&, const A&);
B friend A operator+(const A&, const A&);
C friend operator+();
D operator+(const A&, const A&) friend;