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.
Pointers กับ struct
struct รวมค่าที่เกี่ยวข้องเข้าเป็นประเภทหนึ่ง ที่นี่ struct Point เก็บ x และ y ให้ทำฟังก์ชันสองตัว: make_point สร้างและส่งกลับ Point, และ move_point ย้ายตำแหน่งที่มีอยู่แล้ว ด้วย pointer ไปยัง struct คุณสามารถเข้าถึง field ได้ด้วย -> ดังนั้น 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 ->. · มี struct Point พร้อมกับ int x, y ให้แล้ว เติม 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. · คลิก Run เพื่อดูผลลัพธ์ที่นี่