#include <iostream>

#include<cstring>

using namespace std;

class Student

{

    int Rollno;

    char name[25];

    public:

    void getdata(int rn , char *nm)

    {

        Rollno=rn;

        strcpy(name,nm);

    }

    void display()

    {

        cout<< "\n Roll No: "<< Rollno ;

        cout<< " Name : "<< name << endl;

        

    }

};

 //int size=2;

int main() {

    // Write C++ code here

    cout << "Pointer to Objects  program\n ";

Student *S=new Student[3];

 Student *P=S;

int i, no;

char str[20];


for(i=0;i<3;i++)

{

    cout<<"\n input student's roll no and name "<<i+1<<endl;

    cin>>no>>str;

S->getdata(no,str);

S++;

}

cout<<"\n Students information :\n ";

for(i=0;i<3;i++)

{

    cout<<" student:  "<<i+1;

    P->display();

P++;

}

    return 0;

}

output:

Pointer to Objects  program

 

 input student's roll no and name 1

301 Umesh

input student's roll no and name 2

315 Harish

input student's roll no and name 3

332 Kailas

Students information :

  student:  1

 Roll No: 301 Name : Umesh

 student:  2

 Roll No: 315 Name : Harish

 student:  3

 Roll No: 332 Name : Kailas