Home >Backend Development >C++ >How to pass the address of a structure as a parameter to a function in C language?
Pass the address of the structure to the function as a parameter −
Pass the address of the structure to the function as a parameter.
Collect it into the structure pointer in the function header.
No memory is wasted because there is no need to create a copy
No need to Value is returned because the function can indirectly access the entire structure and operate on it.
#include<stdio.h> struct date{ int day; int mon; int yr; }; main (){ struct date d= {02,01,2010}; display (&d); getch (); } display (struct date *dt){ printf("day = %d</p><p>", dt->day); printf("month = %d</p><p>",dt->mon); printf("Year = %d",dt->yr); }
day = 2 month = 1 Year = 2010
The above is the detailed content of How to pass the address of a structure as a parameter to a function in C language?. For more information, please follow other related articles on the PHP Chinese website!