Points with a struct · 用结构体表示点
Points with a struct
A struct groups related values into one type. Here struct Point holds an x and a y. Complete two functions: make_point builds and returns a Point, and move_point shifts an existing one. With a pointer to a struct you reach its fields with ->, so p->x += dx moves it.
用结构体表示点
struct(结构体)把相关的值组合成一个类型。这里 struct Point 含有 x 和 y。完成两个函数:make_point 构建并返回一个 Point,move_point 平移一个已有的点。通过指向结构体的指针,用 -> 访问它的字段,所以 p->x += dx 就能移动它。
A struct Point with int x, y is given. Complete make_point(int x, int y) to build a Point, and move_point(struct Point *p, int dx, int dy) to shift it by (dx, dy) using ->. · 已给出含 int x, y 的 struct Point。完成 make_point(int x, int y) 来构建一个 Point,并完成 move_point(struct Point *p, int dx, int dy),用 -> 把它平移 (dx, dy)。
Click Run to see the output here. · 点击“运行”查看此处输出。