Difference between != and =! with an example(in C++)

This operation:


determines if A is not equal to B. If they’re not equal, it evaluates to true. If they are equal, it evaluates to false. It’s just a boolean comparison operation.

This operation:


is not a boolean comparison. It sets the value of A to the negated value of B. (When used in this context it also evaluates to the new value of A, but isn’t really a “comparison” in that regard.) So if B is true then this will set the value of A to false. It can be seen much more clearly as:

A = !B

The first operation only compares, it doesn’t modify anything. The second operation modifies A.

Leave a Comment