Q. An operator function is created using _____________ keyword.
β
Correct Answer: (B)
operator
Explanation:
In C++, operator overloading allows you to define how operators (like +, -, *, ==, etc.) behave for objects of your class. To create an operator function, you use the operator keyword.
Example:
class Complex {
public:
int real, imag;
Complex(int r, int i) : real(r), imag(i) {}
// Overload the + operator
Complex operator+(const Complex& other) {
return Complex(real + other.real, imag + other.imag);
}
};
Here, operator+ is the operator function.
β Correct Answer: (B) operator