Datasheet
LOGICAL OPERATORS
Operands of logical operations are considered true or false, that is non-zero or zero.
Logical operators always return 1 or 0. Operands in a logical expression must be of
scalar type.
Logical operators && and || associate from left to right. Logical negation operator !
associates from right to left.
Logical Operators Overview
Logical Operations
Precedence of logical, relational, and arithmetic operators was designated in such
a way to allow complex expressions without parentheses to have an expected
meaning:
c >= '0' && c <= '9'; /* reads as: (c >= '0') && (c <= '9') */
a + 1 == b || ! f(x); /* reads as: ((a + 1) == b) || (! (f(x))) */
Logical AND && returns 1 only if both expressions evaluate to be nonzero, otherwise
returns 0. If the first expression evaluates to false, the second expression will not be
evaluated. For example:
a > b && c < d; /* reads as (a > b) && (c < d) */
/* if (a > b) is false (0), (c < d) will not be evaluated */
Logical OR || returns 1 if either of expression evaluates to be nonzero, otherwise
returns 0. If the first expression evaluates to true, the second expression is not eval-
uated. For example:
a && b || c && d; /* reads as: (a && b) || (c && d) */
/* if (a && b) is true (1), (c && d) will not be evaluated */
200
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5
Operator Operation Precedence
&&
logical AND 5
||
logical OR 4
!
logical negation 14
&&
0 x
0 0 0
x 0 1
||
0 x
0 0 1
x 1 1
!
0 x
1 0