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

27 lines
1.2 KiB
Markdown
Raw Normal View History

2024-10-28 15:21:30 +00:00
1. Suppose that the following declarations are in effect:....
a. `14`
b. `34`
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
```
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.
```c
middle = low + (high - low) / 2;
```
3. What will be the contents of the `a` array after the following statements are executed?
```c
{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
2024-10-28 15:26:30 +00:00
```
5. Suppose that `a` is a one dimensional array and `p` is a pointer variable. assuming that the assignment `p = a` has just been performed, which of the following expressions are illegal because of mismatched types? Of the remaining expressions, which are true (have a nonzero value)?
The following expressions are illegal because of mismatched types:
2024-10-28 15:31:30 +00:00
- (a) `p == a[0]` - Comparison between `int *` and `int`
The rest of the expressions are true.
2024-10-28 16:30:15 +00:00
2024-10-28 16:45:14 +00:00
8.'