/* * struct-param-pointer.c */ struct point { int x; int y; }; int dist_squared(struct point *p1, struct point *p2); int dist_squared_better(struct point *p1, struct point *p2); int main(int argc, char *argv[]) { struct point a, b; float d; a.x = 0; a.y = 0; b.x = 4; b.y = 3; d = dist_squared(&a, &b); } int dist_squared(struct point *p1, struct point *p2) { int dx, dy; dx = (*p1).x - (*p2).x; dy = (*p1).y - (*p2).y; return dx * dx + dy * dy; } int dist_squared_better(struct point *p1, struct point *p2) { int dx, dy; dx = p1->x - p2->x; dy = p1->y - p2->y; return dx * dx + dy * dy; }