&& and || are boolean operators, not logical operators...
They don't execute respectively bit by bit AND and OR logical operations.
Boolean operators consider the whole value (byte, word, doubleword, etc) true if they are not zero.
Ie
if (a)
, is equivalento to
if (a!=0)
.
So the code:
if (a && b)
is equivalent to
if ( (a!=0) && (b!=0) )
A boolean operation gives only two results: 1=TRUE, 0=FALSE
If you want the bit by bit logical operation AND or OR you must use '|' for OR and '&' for AND.
In the following code:
if (a & b)
if a=7 and b=3 the logical result is 3, the boolean result is TRUE because 3!=0.
I hope to have been clear....
Oh I forgot: yes, logical and boolean operators are simmetric.
Moreover the boolean operators are always optimized, so if the first term of an AND operation is false the second one is not evaluated (the reverse for boolean OR). So if the second term of your comparison is a function it is not called.
Ie
if (a && getvalue(b))
If a is false (a=0) the function getvalue is never called.