Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 "Not"
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rar




PostPosted: Wed Oct 07, 2009 7:41 pm   Post subject: "Not"

What is the difference between '~' and '!' in C?

I've been reviewing my notes for an upcoming quiz and was not aware there was a difference...
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Wed Oct 07, 2009 7:49 pm   Post subject: RE:"Not"

~ can be used as a destructor right?

like
code:

Queue();
~Queue();
bbi5291




PostPosted: Wed Oct 07, 2009 7:52 pm   Post subject: Re: "Not"

The ! operator is a logical negation. Applied to zero (false), it yields one (true). Applied to any nonzero value (true), it yields zero (false).
The ~ operator on the other hand is a bitwise negation. When ~ is applied to an integer, every bit in the integer's binary representation is flipped.
DtY




PostPosted: Wed Oct 07, 2009 7:54 pm   Post subject: RE:"Not"

! is logical, ~ is bitwise, ! is the not of || and &&, ~ is the not of | and &.

For example, (I don't know if 0b works in C, but I'll assume it does, it means binary number, assume 8 bit)
!0b00000001 = 0b00000000
~0b00000001 = 0b11111110
!0b00000000 = 0b00000001
~0b00000000 = 0b11111111
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: