#include #include #include struct point { int x; int y; }; struct rect { struct point pt1; struct point pt2; }; struct rect rects[10]; //struct rect { // struct point pt1; // struct point pt2; // } rects[10]; typedef int Length; typedef struct Books { char title[50]; char author[50]; char subject[100]; int book_id; } Book; Book variable; //struct { ... } x, y, z; //int x, y, z; union Data { int i; float f; char str[20]; }; int main(){ struct point pt, p2, p3; struct point maxpt = { 320, 200 }; printf("%d, %d\n", maxpt.x, maxpt.y); pt.x = 320; pt.y = 200; printf("%d, %d\n", pt.x, pt.y); struct point *pp = malloc(sizeof(struct point)); pp->x = 9; pp->y = 8; printf("%d, %d\n",(*pp).x,(*pp).y); free(pp); struct point origin; struct point *po; po = &origin; po->x = 19; po->y = 18; printf("%d, %d\n", po->x, po->y); printf("%d, %d\n", origin.x, origin.y); struct rect screen; screen.pt1.x = 9; screen.pt1.y = 8; struct rect *rp; struct rect r; rp = &r; r.pt1.x = 50; //Las siguientes 4 expresiones son análogas //r.pt1.x //rp->pt1.x //(r.pt1).x //(rp->pt1).x printf("%d\n",r.pt1.x); printf("%d\n",rp->pt1.x); printf("%d\n",(r.pt1).x); printf("%d\n",(rp->pt1).x); union Data data; data.i = 10; printf( "data.i : %d\n", data.i); data.f = 220.5; printf( "data.f : %f\n", data.f); strcpy( data.str, "C Programming"); printf( "data.i : %d\n", data.i); printf( "data.f : %f\n", data.f); printf( "data.str : %s\n", data.str); }