I have a quick question about the following expression:
int a_variable = 0;
if(0!=a_variable)
a_variable=1;
what is the difference between “(0 != a_variable)” and “(a_variable != 0)” ?
I dont have any errors for now but is this a wrong way to use it??
if you forget the
!, the first will give an error(0 = a_variable)and the second will wreak havoc(a_variable = 0).Also, with user-defined operators the second form can be implemented with a member function while the first can only be a non-member (possibly friend) function. And it’s possible, although a REALLY bad idea, to define the two forms in different ways. Of course since
a_variableis anintthen there are no user-defined operators in effect in this example.