Ask Question
7 May, 05:52

Explain by details operator overloading in C+ + with example

+4
Answers (1)
  1. 7 May, 08:06
    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?
Get an answer to your question ✅ “Explain by details operator overloading in C+ + with example ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers