点类定义和使用.cpp 478 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. typedef struct {
  3. int x;
  4. int y;
  5. } Point;
  6. void setxy(Point *point, int new_x, int new_y) {
  7. point->x = new_x;
  8. point->y = new_y;
  9. }
  10. void displayxy(Point point) {
  11. printf("(%d,%d)", point.x, point.y);
  12. }
  13. int main() {
  14. Point point1 = {3, 4};
  15. Point point2 = {5, 6};
  16. printf("The first point is:");
  17. displayxy(point1);
  18. printf("\n");
  19. printf("The second point is:");
  20. displayxy(point2);
  21. printf("\n");
  22. return 0;
  23. }