A

Admin • 833K Points
Coach

Q. An operator function is created using _____________ keyword.

  • (A) iterator
  • (B) operator
  • (C) allocator
  • (D) constructor
  • Correct Answer - Option(B)
  • Views: 22
  • Filed under category C++
  • Hashtags:

Explanation by: Admin

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.