Thursday 6 October 2022

C++ Pointer To Array of Objects | Pointer To Array of Objects in CPP

                  In this post, we will see C++ Pointer To Array of Objects | Pointer To Array of Objects in CPP 


Program Code: (pointers9.cpp)

//Pointer To Array of Objects

#include<iostream>

using namespace std;


class Sample

{

public:

int x;

void show()

    {

        cout<<"Value of x is "<<x<<endl;

    }

};


int main()

{

Sample obj[5];

Sample *p;  


p=obj;  //p=&obj[0]


for(int i=0;i<5;i++)

{

    p->x=i;  //obj[0].x

    p->show();  //obj[0].show();

    p++;

}


}


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=ZWaCx_GueBs


No comments:

Post a Comment