I. Structures as Function Arguments
C provides a means of passing an entire structure to functions as arguments in the function call. A
structure variable is passed like any basic data type.
For example,
#include
display(struct Employee);
struct Employee
{
char name[10];
int age;
float salary;
};
main( )
{
struct Employee emp = {“Rajiv”, 40, 82000.00};
display(emp); /*passing entire structure to display( ) function */
}
display(struct Employee e)
{
printf(“\n Employee Record:”);
printf(“\n Name: %s”, e.name);
printf(“\n Age: %d”, e.age);
printf(“\n Salary: %f”, e.salary);
}
Do'stlaringiz bilan baham: |