ADVERTISEMENT
ADVERTISEMENT

Home » C++ solved programs » C++ operator overloading programs

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

This program will demonstrate example of unary logical NOT (!) operator overloading in c++ programming language.

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.