It is a simple C++ program on “Call by Reference using an objects“. It will perform a reference operation for the given variables. While compiling the call by reference program, input values are getting using the reference. This CPP program can be used for all kind of students like Engineering, Diploma and Arts & Science students for their lab exams and related tests. It may be useful for their exam purpose.
CALL BY REFERENCE USING OBJECTS
This C++ program is talking about call by reference method is done using objects. There is no parameters and all. Objects are takes place.
[SEE: IT Related Abroad Studies] & [Bike Back Wordings]
PROGRAM:
/* Title: Call by reference Author: Karthikh Venkat © http://students3k.com This website provides lots of useful information for all students. */ //Header Files. #include <iostream.h> #include <conio.h> class students3k { int k; public: //Variables declaration. int i; students3k(int i); ~students3k(); void neg(students3k &o) { o.i = -o.i; } // No Temporary Created. }; students3k::students3k(int num) //Method { cout << "Constructing:" << num << "\n"; k = num; } students3k::~students3k() { cout << "Destructing:" << k << "\n"; } int main() { clrscr(); //For clear the previous output screen. students3k o(1); o.i = 10; o.neg(o); cout << o.i << "\n"; //Display your Output. getch(); return 0; }