These operators pertain are used in conditionals, comparisons and logic operations. Most should look very familiar.
| OP | Name | Example | Description |
|---|---|---|---|
>
|
Greater than | x>y
|
1 if x>y, else 0
|
>=
|
Greater/equal | x>=y
|
1 if x>=y, else 0
|
<
|
Less than | x<y
|
1 if x<y, else 0
|
<=
|
Less/equal | x<=y
|
1 if x<=y, else 0
|
==
|
Equal to | x==y
|
1 if x = y, else 0
|
!=
|
Not equal to | x!=y
|
1 if not x==y, else 0
|
!
|
Logical NOT | !x
|
1 if x is zero, else 0
|
&&
|
Logical AND | x&&y
|
1 if both x and y non-zero, else 0
|
||
|
Logical OR | x||y
|
1 if either x or y non-zero, else 0
|
As you can see, all these operations return one of two possible values: 1 to signify Boolean true, 0 for Boolean false. The same thing goes on in Oric BASIC. Although the logical and conditional operators return only 1 or 0, they consider any non-zero value as True.
Greater Than, Less Than, etc.
BASIC users, beware! The ‘greater than/equal to’ and ‘less than/equal to’ operators have to be written exactly as shown: C won't recognise ‘=>’ as ‘greater than or equal to’.
Equality (==)
You should be very careful of this one. Do not confuse it with the assignment operator (=). To check two expressions for equality, only use ==. In many cases the compiler will warn you if you confuse them, but not always.
Inequality (!=)
No surprises here. Just remember that <> does not work in C!
AND (&&), OR (||)
These work just as they do in all programming languages. An important note: && and || are Boolean operators. There is another set of operators for dealing with bit values. This means, for example, that 255 && 31 will return 1 (remember, this set of operators considers all non-zero values as 1). I cannot stress it enough, but remember: careless use of these logical operators is the source of many bugs in C programs.
NOT (!)
This is a unary operator. Put it before an expression, and it will return 0 if the expression is non-zero, and 1 if the expression evaluates to zero. Just your ordinary Boolean NOT operator. Let me again caution you: ! will not reverse bit values! It, too, only deals with zero and non-zero values. Bit-wise negation is handled by another operator.




Add new comment