vault backup: 2024-09-18 11:42:12

This commit is contained in:
zleyyij 2024-09-18 11:42:12 -06:00
parent e1d0e5756f
commit 0ac24032c0

View File

@ -40,9 +40,23 @@ printf("%d", i < j || k);
``` ```
> 6. Is the following `if` statement legal? > 6. Is the following `if` statement legal?
```c ```c
if (n >= 1 <= 10) if (n == 1-10)
printf("n is between 1 and 10\n"); printf("n is between 1 and 10\n");
``` ```
Yes the statement is *legal*, but it does not produce the intended effect. It would produce an output when `n` is zero because `0 >= 1` would evaluate to `0`, and `0 <= 10` is false.
Yes the statement is *legal*, but it does not produce the intended effect. It would not produce an output when `n = 5`, because `1-10` evaluates to `-9`, and `-9 != 5`.
> 10. What output does the following program fragment produce? (Assume that `i` is an integer variable.)
```c
int i = 1;
switch (i % 3) {
case 0: printf("zero");
case 1: printf("one");
case 2: printf("two");
}
```
The program would print `onetwo` because each case is missing a `break` statement.
> 11. The following table shows the telephone ar