notes/education/software development/ECE1400/Chapter 11 Exercises.md

20 lines
767 B
Markdown
Raw Normal View History

2024-10-25 19:46:54 +00:00
1. Suppose that the following declarations are in effect:....
a. `14`
b. `34`
2024-10-25 19:51:54 +00:00
c. `4`
d. `true`
e. `false`
2. Suppose that `high`, `low`, and `middle` are all pointer variables of the same type, and the `low` and `high` point to elements of an array. Why is the following statement illegal, and how could it be fixed?
```c
middle = (low + high) / 2
```
2024-10-25 20:06:54 +00:00
The above statement is illegal because you can't add an `int *` to an `int *`. The below operation is legal because you can perform pointer subtraction, and because `low` is defined on the left hand side of the equation, then adding a long to a pointer is valid.
2024-10-25 20:01:54 +00:00
```c
2024-10-25 20:06:54 +00:00
middle = low + (high - low) / 2;
```
3. What will be the contents of the `a` array after the following statements are executed?
```c
{1}
2024-10-25 20:01:54 +00:00
```