Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between != and =! in Java? [duplicate]

Tags:

java

syntax

People also ask

Is != Same as =!?

The != operator is an equality operator that is used to check whether two operands are equal or not. The =! operator is a combination of two operators, one is an assignment, and the second is a negation operator that works on boolean value.

What is the difference between != and =! In C?

A!= B means " A is not equal to B ". A=! B means "Assign the complement of B to A , and yield the lvalue of A ".

Is it += or =+ Java?

=+ does nothing; it's the same as = here. You have just written sum1 = two . sum2 += one on the other hand is essentially the same as sum2 = sum2 + one .

What is difference == and === in Java?

== === = in JavaScript is used for assigning values to a variable. == in JavaScript is used for comparing two variables, but it ignores the datatype of variable. === is used for comparing two variables, but this operator also checks datatype and compares two values.


The question is just playing with you with confusing spacing.

b != b is the usual != (not equals) comparison.

On the other hand:

b =! b is better written as b = !b which is parsed as:

b = (!b)

Thus it's two operators.

  1. First invert b.
  2. Then assign it back to b.

The assignment operator returns the assigned value. Therefore, (b =! b) evaluates to true - which is what you print out.


b != b means ! (b == b): the opposite of b == b.

b =! b is actually b = !b, an assignment. It's toggling b's value. An assignment evaluates to the value of the expression, so this will evaluate to !b (along with having changed the value of b).


b=!b is an assignment. It assigns b to !b and the expression evaluates to the resulting value, which is true.


b =! b

you are doing an assignment, you are saying that B should have the value of !B.

b != b

You are asking if B is different than b