C Language



Admission Enquiry Form

  

Passing Structure to Function by Reference in C


Passing Structure to Function by Reference in C

Passing structure to function by reference means we call the function by passing the address of structure to a function as an argument.

Example:

#include<stdio.h>
struct student
{
int rollno;
char name[10];
int fee;
}st;

void main()
{
void display(struct student*);
printf("Enter name : ");
scanf("%s",&st.name);
printf("Enter rollno : ");
scanf("%d",&st.rollno);
printf("Enter fee : ");
scanf("%d",&st.fee);
display(&st);
}
void display(struct student *st)
{
printf("\n Name is %s",st->name);
printf("\n Rollno is %d",st->rollno);
printf("\n Fee is %d",st->fee);
}

Output

Enter name : sunil
Enter rollno : 40
Enter fee : 8000

Name is sunil
Rollno is 40
Fee is 8000