C++ Program For Reference Object

Free C++ course with real-time projects Start Now!!

Program 1

//Program by Object reference  (Pointer Object)
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Abc
{
    int n;
    public:
    Abc()
    {
        cout<<"\n I am constructor\n";
        n=10;
    }
    void incr()
    {
       ++n;
    }
    void display()
    {
        cout<<n;
    }
};
int main()
{
    clrscr();
    Abc A; // Actual Object
    Abc *B; // Reference Object
    B=&A;
    A.incr();
    A.incr();
    B->display();
    B->incr();
    A.display();
    return 0;
}

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *