Any difference it may make is the order in which the arguments will be evaluated. a != b
would conventionally evaluate a
, then evaluate b
and compare them, while b != a
would do it the other way round. However, I heard somewhere that the order of evaluation is undefined in some cases.
It doesn't make a big difference with variables or numbers (unless the variable is a class with overloaded !=
operator), but it may make a difference when you're comparing results of some function calls.
Consider
int x = 1;
int f() {
x = -1;
return x;
}
int g() {
return x;
}
Assuming the operands are evaluated from left to right, then calling (f() != g())
would yield false
, because f()
will evalute to -1
and g()
to -1
- while (g() != f())
would yield true
, because g()
will evaluate to 1
and f()
- to -1
.
This is just an example - better avoid writing such code in real life!