T2U4_Pointer_to_class_and_object
T2U4_Pointer_to_class_and_object
· We know that a pointer is a variable that holds the address of another data variable.
· The variable may be of any data type , that is int , float m or double .
· In the same way , we can also define pointer to class . Here , the starting address of the member
variable can be accessed , thus such pointer are called class pointers
Example
class book
char name[30];
int pages;
};
(or)
in the above example , *ptr is a pointer to a class book , both statements (a) and (b) are alid the syntax
for using pointes with members is as given below
by executing thses three statements , the starting address of each member can be estimated.
Pointer to Object
Similar to variable , objects also have on address . A pointe can point to a specified object
#include<iostream.h>
#include<conio.h>
class man
public:
char name[20];
int age;
};
void main()
clrscr();
man m={"krish",34};
man *ptr;
ptr=&m;
cout<<"\n name:"<<m.name;
getch();