/*Passing Structures to Functions by CBR*/ #include // define a structure template struct demo{ int a; char *str; int *ptr; }; //function prototype void f1(struct demo parm, struct demo *parm_ptr); int main(void) { int value = 1; struct demo arg, *arg_ptr=&arg; arg.a = 100; arg.str = "hello"; arg.ptr = &value; f1(arg, arg_ptr); //CBV & CBR return 0; } void f1(struct demo parm, struct demo *parm_ptr) { printf("%d %d %d %s %s %d %d\n", parm.a, parm_ptr->a, (*parm_ptr).a, (*parm_ptr).str, parm_ptr->str, *(parm_ptr->ptr), *((*parm_ptr).ptr)); } /*Note: 1. When a pointer to a structure is passed to a function, only the address of the structure is pushed on the stack. This makes for very fast function call. 2. Passing a pointer makes it possible for the function to modify the contents of the structure used as the argument. */