PROGRAM TO IMPLEMENT THE CONCEPT OF POINTER TO AN OBJECT

/*PROGRAM TO IMPLEMENT THE CONCEPT OF POINTER TO AN OBJECT*/

#include<conio.h>

#include<iostream.h>

#include<stdio.h>

class student

{

int roll_no,age;

char name[15];

public:

void input();

void output();

};

void student::input()

{

cout<<“Enter name of the student: “;

gets(name);

cout<<“Enter roll no of the student: “;

cin>>roll_no;

cout<<“Enter age of the student: “;

cin>>age;

}

void student::output()

{

cout<<“Name: “<<name<<endl;

cout<<“Roll no: “<<roll_no<<endl;

cout<<“Age: “<<age;

}

void main()

{

student *ptr;

clrscr();

(*ptr).input();   //USING INDIRECTIONAL OPERATOR

cout<<“Data of student is: “<<endl;

ptr->output();    //USING POINTER STRUCUTRE OPERATOR

getch();

}

Leave a Reply

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