A program illustrating how to pass reference to object as a function argument in C++

 A program illustrating how to pass reference to object as a function argument

Program Explanation :
Here in the putdata() function we have passed reference to object to modifiy the data member from within the member function via it's Object.

Program :-
#include<iostream,h>
class ABC
{
public:
int data;
void getdata()
{
cout<<"Enter number:";
cin<<data;
cout<<"You entered:"<<data;
}
void putdata(ABC &obj)
{
obj.data=-obj.data;
cout<<"Now number is changed to:"<<obj.data;
}
};
void main()
{
ABC obj1;
obj1.getdata();
obj1.putdata(obj1);
}

Output is :

Entered number : 10
You entered : 10
Now number is changed to :    -10

Comments

Popular posts from this blog

How to make a snake game using notepad using html [ with pictures ]

Program to find Addition of "n" numbers useing for loop

how to speed up your internet using cmd [command prompt] with pictures [100% working]