Ask Question
12 October, 07:54

Explain by details operator overloading in C+ + with example

+3
Answers (1)
  1. 12 October, 10:26
    0
    Operator overloading is used to extend the functionality of an operator like + (addition), - (subtraction), / (Division), * (Multiplication).

    Syntax for operator overloading inside the class : -

    You have to use operator keyword.

    Function

    return type operator (arguments)

    {

    ---code

    }

    suppose you want to extend the functionality of + + operator for any integer so that it increases the value by two.

    void operator + + (int &a)

    {

    a=a+2;

    }

    So whenever this operator is used with an argument it will increase the value to that argument by 2.

    int a=5;

    + + (a);

    a will become 7;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Explain by details operator overloading in C+ + with example ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers