Ask Question

Explain by details operator overloading in C+ + with example

+2
Answers (1)
  1. 4 August, 14:07
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers