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 .

    #include<iostream>
    using namespace std;  
    struct Employee
    {
        char name[20];
        int age;
        int salary;
    }E;
    void display(struct Employee E);
    int main()
    {
        struct Employee E;
        cout<<"\nEnter the Name :";
        cin>>E.name;
        cout<<"\nEnter the Age :";
        cin>>E.age;
        cout<<"\nEnter the Salary :";
        cin>>E.salary;
        cout<<"---------------------------------\n";
        display(E);
        return (0);
    }
    void display(struct Employee E)
    {
        cout<<"\nName : "<<E.name;
        cout<<"\nAge : "<<E.age;
        cout<<"\nSalary : "<<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