Structure-as-function-argument-in-c .

In this session i have discussed structure as function argument in C .


Here we will learn how to pass the structure as function argument .


Example : Write a C program demonstrate the struct as function argument .

    #includ<stdio.h> 
    #include<string.h>
    struct Employee
    {
        char name[20];
        int age;
        int salary;
    }E;
    void display(struct Employee E);
    int main()
    {
        struct Employee E;
        printf("\nEnter the Name :");
        scanf("%s",&E.name);
        printf("\nEnter the Age :");
        scanf("%d",&E.age);
        printf("\nEnter the Salary :");
        scanf("%d",&E.salary);
        printf("---------------------------------\n");
        display(E);
        return (0);
    }
    void display(struct Employee E)
    {
        printf("Name : %s\n",E.name);
        printf("Age : %d\n",E.age);
        printf("Salary : %d\n",E.salary);
    }
    OUTPUT : Enter the Name : Rakesh
             Enter the Age  : 20
             Enter the Salary : 20000
             -------------------------------------
             Name : Rakesh
             Age : 20
             Salary : 20000
    

Welcome to AndroidATPoint.

back image                     next image