Comparison operators  Bitwise operators

Chapter 1: Overview

Logical operators

Logical operators are grouped left to right. When a statement contains more than one logical operator, the operations are performed in their order of precedence. See “Operator order of precedence” for information about the precedence of the logical operators. Use parenthesis ( ) to perform operations in non-precedence order. In the examples below, “a”, “b”, “c”, and “d” are integer data.

Table 1-5: Logical operators

Operator

Description

Returns

Example

!

Logical NOT

One (1) if true, and zero (0) if false.

a = !b;

“a” is 1 when “b” is 0, and “a” is 0 when “b” is non-zero.

||

Logical OR

One (1) if either expression is non-zero, otherwise returns zero (0).

The second expression is not evaluated if the value of the first expression is non-zero.

d = a > b || c < b;

“d” is 1 when either expression’s value is non-zero.

&&

Logical AND

One (1) if both expressions are non-zero, otherwise returns zero(0).

The second expression is not evaluated if the value of the first expression is zero.

if (a > b && c < d) ...

Is 1 when both expression’s values are non-zero.





Copyright © 2005. Sybase Inc. All rights reserved. Bitwise operators

View this book as PDF