write a program in program notebook for pass by reference to user defined function
For Example: Write a program to create structure as employee and accept idno, name of employee , city and salary of employee and pass it to the user defined function by using pass by reference
#include<stdio.h>
#include<conio.h>
struct employee
{
int idno;
char ename[20];
char city[10];
float salary;
};
void output(struct employee *ep);
int main()
{
struct employee e;
printf("\n Enter ID number:");
scanf("%d",&e.idno);
printf("\n Enter name of Employee: ");
scanf("%s",&e.ename);
printf("\n Enter City of Employee:");
scanf("%s",&e.city);
printf("\n Enter Salary of Employee");
scanf("%f",&e.salary);
output(&e); // Calling function (passing structure
variable stud as argument)
getch();
return 0;
}
void output(struct employee *ep) //Function definition
{
printf("\n Employee Id
is: %d",ep->idno);
printf("\n Name of Employee is: : %s",ep->ename);
printf("\n City of Employee is: %s",ep->city);
printf("\n Salary of Employee is:
%f",ep->salary);
}
Output :
Comments
Post a Comment