/** * A gentle intro to structs. * Illustrates lots of points * * @author gtowell * Created March 20, 2021 * **/ #include // define a struct struct p { int a; int b; }; // define a struct using typedef typedef struct { int a; int b; } pType; //print constent of struct using basic define void printit(struct p pa) { printf("struct p %d %d %d\n", &pa, pa.a, pa.b); } // print contents of struct using typedef void printitPT(pType pa) { printf("pType %d %d %d\n", &pa, pa.a, pa.b); } // print contents of struct, when passed by reference void printitPoint(pType * paP) { // note use of two ways to get to pointed to struct contents // -> is just shorthand and is supposed to be easier. printf("pType* %d %d %d\n", paP, (*paP).a, paP->b); } int main(int argc, char const *argv[]) { struct p aa; aa.a = 5; aa.b = 10; pType bb = {.a=6, .b=12}; printf("Pointers %d %d\n", &aa, &bb); printit(aa); printitPT(bb); printitPoint(&bb); return 0; }