Points with a struct · Điểm với 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.
Con trỏ với struct
Một struct nhóm các giá trị liên quan vào một kiểu dữ liệu. Ở đây struct Point chứa một x và một y. Hoàn thành hai hàm: make_point tạo và trả về một Point, và move_point dịch chuyển một điểm đã tồn tại. Với con trỏ đến struct, bạn truy cập các trường của nó bằng ->, do đó p->x += dx di chuyển nó.
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 ->. · Một struct Point với int x, y được đưa ra. Hoàn thành make_point(int x, int y) để xây dựng một Point, và move_point(struct Point *p, int dx, int dy) để dịch chuyển nó theo (dx, dy) bằng ->.
Click Run to see the output here. · Nhấn Chạy để xem kết quả ở đây.