Points with a struct · נקודות עם מבנה (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 מזיז נקודה קיימת. עם רמישה (pointer) למבנה מגיעים לשדות שלו באמצעות ->, ולכן 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) כדי לבנות נקודה, והשלם move_point(struct Point *p, int dx, int dy) כדי להזיז אותה ב-(dx, dy) באמצעות ->.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.