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 は関連する値を1つの型にまとめます。ここでは struct Point が x と y を保持しています。2つの関数を完成させてください: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 ->.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。