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

31 lines
767 B
Markdown
Raw Normal View History

2024-11-19 21:10:06 +00:00
> **4.** Suppose that the following declarations are in effect:
2024-11-19 21:05:06 +00:00
```c
2024-11-19 21:10:06 +00:00
struct point {int x, y; };
struct rectangle { struct point upper_left, lower_right; };
struct rectangle *p;
2024-11-19 21:05:06 +00:00
```
2024-11-19 21:10:06 +00:00
> Assume that we want `p` to point to a rectangle structure whose upper left corner is at $(10, 25)$, and whose lower right corner is at $(20, 15)$. Write a series of statements that allocate such a structure and initialize it as indicated.
2024-11-19 21:05:06 +00:00
2024-11-19 21:15:06 +00:00
```c
struct rectangle rect = { { 10, 25 }, { 20, 15 } };
p = ▭
```
---
2024-11-19 21:20:06 +00:00
> **5.** Suppose that `f` and `p` are declared as follows:
```c
struct {
union {
char a, b;
int c;
} d;
int e[5];
} f, *p = &f;
2024-11-19 21:25:06 +00:00
```
> Which of the following statements are legal?
(a) `p->b = ' ';`
(b) `p->e[3] = 10;`
(c) `(*p).d.a = '*';`
(d) `p->d->c = 20;`