Pointer to derived class: Pointers can be used to point to the base class objects and objects of derived class. Pointers to objects of base class are type-compatible with pointers to objects of a derived class. Single pointer variable can be made to point objects belonging to different classes. If B is base class and D is derived class then pointer declared as a pointer to B can also be a pointer to D.
Example:
B *cptr; // pointer of base class
B b;//Base object
D d;// Derived object
cptr=&b; //cptr stores address of object b of base class
cptr=&d; //cptr stores address of object d of derived class
Using cptr, pointer of base class type, we can access only those members which are inherited from B and not the members that originally belong to D.In case a member of D has the same name as one of the members of B,then any reference to that member by cptr will always access the base class member.