56 lines
912 B
C
56 lines
912 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
struct point {
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
struct {
|
|
int x;
|
|
int y;
|
|
} point2;
|
|
|
|
struct point3 pt;
|
|
|
|
struct point3 {
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
struct rect {
|
|
struct point pt1;
|
|
struct point pt2;
|
|
};
|
|
|
|
struct point makepoint(int, int);
|
|
struct point *makepoint_p(int, int);
|
|
|
|
int main() {
|
|
struct point p = {2, 3};
|
|
printf("x: %d, y: %d\n", p.x, p.y);
|
|
|
|
struct rect r1 = {{2, 3}, {3, 4}};
|
|
printf("pt1.x: %d, pt1.y: %d, pt2.x: %d, pt2.y: %d\n", r1.pt1.x, r1.pt1.y,
|
|
r1.pt2.x, r1.pt2.y);
|
|
|
|
struct point p2 = makepoint(3, 4);
|
|
printf("x: %d, y: %d\n", p2.x, p2.y);
|
|
|
|
struct point *p3 = makepoint_p(3, 4);
|
|
printf("x: %d, y: %d\n", p3->x, p3->y);
|
|
free(p3);
|
|
}
|
|
|
|
struct point makepoint(int x, int y) {
|
|
struct point p = {x, y};
|
|
return p;
|
|
}
|
|
|
|
struct point *makepoint_p(int x, int y) {
|
|
struct point *p = malloc(sizeof(struct point));
|
|
p->x = x;
|
|
p->y = y;
|
|
|
|
return p;
|
|
}
|