|
Home ► Lab Exercise ► Object Oriented Programming Lab Exercise Programs ► CPP Program For Declaring Pointers as Class Member▼
CPP Program For Declaring Pointers as Class Member |
Alogarithm steps:
- 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
CPP Program For Declaring Pointers as Class Member
#include
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;
}
SAMPLE INPUT AND OUTPUT:
1
|
|
⇓ Student Projects ⇓
⇑ Student Projects ⇑
|