Ranked Best B-School by Rajasthan Technical University
Ranked 2nd within Category-A for 2019-20 in MCA
Awarded the ” LILAVATI AWARD -2020″ by the Government of India, AICTE.

Pointers to Objects

We can have pointers to other types of variables; you can have pointers to objects. When accessing members of a class given a pointer to an object, use the arrow (–>) operator instead of the dot operator.
This program illustrates how to access an object given a pointer to it:
OUTPUT: – 88. As we know, when a pointer is incremented, it points to the next element of its type. For example, an integer pointer will point to the next integer. In general, all pointer arithmetic is relative to the base type of the pointer. The same is true of pointers to objects. For example, this program uses a pointer to access all three elements of array ob after being assigned ob’s starting address:
OUTPUT: 1, 2, 3,4.We can allocate the address of a public member of an object to a pointer and then access that member by using the pointer. Another example-
OUTPUT: 1 Because ptr is pointing to an integer, it is declared as an integer pointer. It is irrelevant that i is a member of ob in this situation.

Author: Admin
Scroll to Top