CS2263/Final/FinalCode/structs/structs.c

43 lines
795 B
C
Raw Normal View History

2023-05-22 23:28:51 -03:00
#include <stdio.h>
#include <stdlib.h>
typedef struct point{
int x;
int y;
int z;
}Point3D;
typedef struct point2 {
int *points;
}Point3DArray;
void printPoint(Point3D p){
printf("(%d, %d, %d)\n", p.x, p.y, p.z);
}
void printPoint2(Point3DArray p){
printf("(%d, %d, %d)\n", p.points[0], p.points[1], p.points[2]);
}
int main() {
Point3D p1;
p1.x = 1;
p1.y = 2;
p1.z = 3;
printPoint(p1);
Point3D *p2 = malloc(sizeof(Point3D));
p2->x = 4;
p2->y = 5;
p2->z = 6;
printPoint(*p2);
Point3DArray *p3 = malloc(sizeof(Point3DArray));
p3->points = malloc(sizeof(Point3D) * 3);
p3->points[0] = 7;
p3->points[1] = 8;
p3->points[2] = 9;
printPoint2(*p3);
return 0;
}