Q:

C++ program for unary logical NOT (!) operator overloading

0

C++ program for unary logical NOT (!) operator overloading

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Unary logical NOT (!) operator overloading program in c++.

 

/*C++ program for unary logical NOT (!) operator overloading.*/
 
#include<iostream>
using namespace std;
 
class NUM
{
    private:
        int n;
         
    public:
        //function to get number
        void getNum(int x)
        {
            n=x;
        }
        //function to display number
        void dispNum(void)
        {
            cout << "value of n is: " << n;
        }
        //unary ! operator overloading
        void operator ! (void)
        {
            n=!n;
        }
};
int main()
{
    NUM num;
    num.getNum(10);
    cout << "Before calling Operator Overloading:";
    num.dispNum();
    cout << endl;
     
    !num;
    cout << "After  calling Operator Overloading:";
    num.dispNum();
    cout << endl;
    return 0;   
}

Output

 
    Before calling Operator Overloading:value of n is: 10
    After  calling Operator Overloading:value of n is: 0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now