C – Structure as Parameter

Program to pass structure as parameter to function:

  • Functions can take structure as input parameter.
  • We pass the structure variable as parameter and collect into same type of structure variable.
#include<stdio.h>
struct Employee
{
            int id;
            char name[20];
            float salary;
};
void display(struct Employee);
int main()
{
            struct Employee x = {101, “Amar”, 35000};
            display(x);
            return 0;          
}
void display(struct Employee y)
{          
            printf(“Emp id : %d \n”, y.id);
            printf(“Emp name : %s \n”, y.name);
            printf(“Emp salary : %f \n”, y.salary);
}
Scroll to Top