You can pass a structure to a function either by value or by reference. When passed by value, a copy of the structure is created. When passed by reference, the function receives a pointer to the structure.
Example of passing by value:
void displayEmployee(struct Employee emp) {
printf("ID: %d\n", emp.empId);
printf("Name: %s\n", emp.empName);
printf("Salary: %.2f\n", emp.empSalary);
}
// Calling the function
displayEmployee(emp1);
Example of passing by reference:
void displayEmployee(struct Employee *emp) {
printf("ID: %d\n", emp->empId);
printf("Name: %s\n", emp->empName);
printf("Salary: %.2f\n", emp->empSalary);
}
// Calling the function
displayEmployee(&emp1);