In lesson 3.5, we studied bitwise logical operators. The logical operations were then applied bit by bit. The logical operators studied in this course work according to the following rule:
Here are some examples:
0 is faux15 is true12.5 is true3<2 is false'r' is trueThere are three logical operators:
| Operator | Name | Type |
|---|---|---|
&& |
logical AND | binary |
|| |
logical OR | binary |
! |
logical NOT | unary |
As for the comparison operators, these operators can only return 0 or 1.
The returned value is always of integer type (int).
These operators are mostly used to combine comparisons:
if (a<5 && a>10)
...
For a logical operator, the value -5 is considered as ....
What should be the type of the variable x?
x = 1 || 0;
int
Try again...
What is the bitwise logical operator AND?
& with the logical operator &&.
Try again...
What does the following program display?
printf ("%d", 1565 || 0);
What does the following program display?
printf ("%d", (12 || 0) && 127);
How to test if p is between 0 and 100 inclusive?
p must be greater than 0 AND less than 100.
Try again...
What is the equivalent instruction?
x = !(a<b);
! inverts the logical proposition a<b.
Try again...