To create a pointer to a private data member of a class, outside

to-create-a-pointer-to-a-private-data-member-of-a-class-outside

To create a pointer to a private data member of a class, outside the class, which among the following is correct?

A. Return the address of the private data member using a member function

B. Access the private member using a pointer outside class

C. Declare the member as pointer inside the class

D. Not possible to create pointer to a private member

I had been asked this question in an international level competition.

This intriguing question originated from Data Members in section Class Members & Types of Object Oriented Programming

The correct choice is A. Return the address of the private data member using a member function

The best explanation: We can call a public member function and return the address of any private data member. Though the pointer being returned must be defined inside class itself. And the returned address can be stored in a pointer.