Now that we can use an indirect reference (a pointer) to a structure variable as easily as we can with a direct reference (a variable identifier) to a structure variable, we can use the indirect reference in function parameters to avoid the unnecessary copying of structures to temporary function variables. We can use the structure pointer in function parameters, as follows:
void printDate( Date* pDate );
We declare the pointer to the structure type in the function declaration. We then define the function, accessing each element as follows:
void printDate( Date* pDate ) {
int m, d , y;
m = pDate->month;
d = pDate->day;
y = pDate->year;
printf( "%4d-%2d-%2d\n" , y , m , d );
// or
printf( %4d-%2d-%2d\n" , pDate->year , pDate->month , pDate->day );
}
In the definition of printDate(), we can create local variables and assign the dereferenced pointer values to them...