what is meaning of ~ operator?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vindyusha
    New Member
    • Mar 2013
    • 1

    what is meaning of ~ operator?

    what is the meaning of ~
    for ex
    ~a=?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The ~ operator is overloaded. In C it is the complement operator. In C++ it is either the complement operator or it identifies a member function as a destructor.

    You haven't posted enough code for me to see what you are after.
    Last edited by weaknessforcats; Mar 8 '13, 03:33 PM. Reason: I mistakenly called this the NOT operator (!).

    Comment

    • VanessaMeacham
      New Member
      • Sep 2012
      • 31

      #3
      Hi ! ~ it is called Complement. it is Bitwise Operator in c. The compl. operator is the text equivalent of ~. There are two ways to access the compl operator in your programs: include the header file iso646.h, or compile with /Za.

      Example :

      Code:
      // expre_One_Complement_Operator.cpp
      // compile with: /EHsc
      #include <iostream>
      
      using namespace std;
      
      int main () {
         unsigned short y = 0xFFFF;
         cout << hex << y << endl;
         y = ~y;   // Take one's complement
         cout << hex << y << endl;
      }
      In my example the new value assigned to y is the one's complement of the unsigned value 0xFFFF, or 0x0000.
      Last edited by Rabbit; Mar 8 '13, 04:36 PM. Reason: Please use code tags when posting code.

      Comment

      • simum
        New Member
        • Mar 2013
        • 4

        #4
        This operator is also used as a destructor..
        for ex:
        Code:
        using system
        class xyz()
        {
        public xyz()
        {
        console.writeline("created");
        }
        [B]~xyz()[/B]
        {
        console.writeline("destroyed");
        }
        }
        [B]or in other cases it can be used as a bitwise operator :)[/B]

        Comment

        Working...