2024-09-18 16:52:12 +00:00
> 2. The following program fragments illustrate the logical operators. Show the output produced by each, assuming that `i`, `j`, and `k` are `int` variables.
a. `i = 10; j = 5;`
2024-09-18 17:12:12 +00:00
```c
2024-09-18 16:57:12 +00:00
printf("%d", !i < j ) ;
2024-09-18 17:12:12 +00:00
// Expected output: `1` , because `!i` evaluates to 0, and 0 is less than 5, so that expression evaluates to true, or 1.
```
2024-09-18 17:17:12 +00:00
b. `i = 2; j = 1;`
```c
printf("%d", !!i + !j);
// Expected output: `1` , because !!2 evaluates to 1, and !j evaluates to 0
```
c. `i = 5; j = 0; k = -5;`
```c
printf("%d", i & & j || k);
2024-09-18 17:22:12 +00:00
// Expected output: `1` , because i && j should evaluate to 0, but `0 || 1` should evalulate to true.
2024-09-18 17:17:12 +00:00
```
2024-09-18 17:22:12 +00:00
d. `i = 1; j = 2; k = 3;`
```c
printf("%d", i < j | | k ) ;
```