Thursday 13 September 2012

Receiving structure from the Function using call by value and call by reference

Note:- call by reference is under construction. Will save the Modified one as soon as it is Finished.





#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct person{
        char name[50];
        int age;
};

person getdata_val()
{
        person p1;
        cout<<"Enter the Person name:- ";
        gets(p1.name);
        cout<<"Enter Age of person:- ";
        cin>>p1.age;
        return (p1);
}

/*=============Under Construction====================
person *getdata_ref()
{
        person p1;
        cout<<"Enter the Person name:- ";
        gets(p1.name);
        cout<<"Enter Age of person:- ";
        cin>>p1.age;
        return (&p1);
}

====================================================*/
void main()
{
        clrscr();
        person p1,*p2;
        p1=getdata_val();
        cout<<"\n====================================================\n";
        cout<<"\nDisplay After Receiving Structure from Function by call by value";
        cout<<"\nName of the Person is :- "<<p1.name;
        cout<<"\nAge of the Person is :- "<<p1.age;
/*=============Under Construction====================
        p2=getdata_ref();
        cout<<"\n====================================================\n";
        cout<<"\nDisplay After Receiving Structure from Function by call by reference";
        cout<<"\nName of the Person is :- "<<p2->name;
        cout<<"\nAge of the Person is :- "<<p2->age;
====================================================*/

        getch();
}

No comments:

Post a Comment