programming-examples/c++/1_Overview/CPP Program For Declaring Pointers as Class Member.cpp
2019-11-15 12:59:38 +01:00

35 lines
524 B
C++

// Start the program
// Create the class and declare the data members and member functions
// Declare the pointer and store the address of data in the pointer
// Create the object and call the function in the main program
// Compile and execute the program
#include<iostream.h>
class c1
{
public:
int i;
c1(int j)
{
i = j;
}
};
int main()
{
c1 ob(1);
int *p;
p = &ob.i; //get address of ob.i
cout<<*p; // access ob.i via p
return 0;
}