| structures/point-rect-0.c - Basalt eksempel på structures i structures. | Lektion 12 - slide 14 : 36 Program 1 |
#include <stdio.h>
struct point {
int x, y;
};
struct rectangle {
struct point p1, p2;
};
int main(void) {
struct point pt1, pt2;
struct rectangle r;
/* Member-wise initialization of x,y coordinates in points */
pt1.x = 5; pt1.y = 6;
pt2.x = 7; pt2.y = 8;
/* Member-wise initialization of points in rectangle */
r.p1 = pt1; r.p2 = pt2;
/* Printing corner points of r */
printf("Corner points in r: (%d,%d) and (%d,%d)\n",
r.p1.x, r.p1.y, r.p2.x, r.p2.y);
return 0;
}