Passing Structure to a Function by Value and by Reference




 This video tutorial explains how to pass structure to a function by value and reference.

You will learn how to pass a structure to a function by value, how to access the structure members when they are passed to a function by value, what happens when we change the value of a structure member when it is passed by value, how to pass the address of a structure variable to a function, how to pass a structure to a function by reference, how to access the structure members when they are passed to a function by reference, what happens when we change the value of a structure member when it is passed by reference in detail with example.

source code for this tutorial

#include <iostream>

using namespace std;

struct student {
    int rollno;
    char sex;
    int age;
};


void display(student s);
void show(student *s);


int main()
{
    student anil = {1234,'m',24};
    show(&anil);

    cout <<endl;

    display(anil);

    return 0;
}

void display(student s){
    cout << s.rollno <<endl;
    cout << s.sex <<endl;
    cout << s.age <<endl;
    s.rollno = 0000;
}

void show(student *s){
    cout << s->rollno <<endl;
    cout << s->sex <<endl;
    cout << s->age <<endl;
    s->rollno = 0000;

}