+ 1

Can you give a programme for pointers to objects

7th Apr 2021, 4:48 PM
Rangu Sanjay
Rangu Sanjay - avatar
2 Respostas
+ 2
Here is c++ source for a program with pointers to objects. It has a pointer to an int and a pointer to an instance of a class which is also known as an object. #include <iostream> using namespace std; class Point { public: int z=0; }; int main() { int x = 5; int * y = &x; // y is a pointer. // y has the address of x. // In other words, y is a pointer to x. cout << (*y) << endl; Point p; // instance of a class. p.z=3; Point * objectPointerToP = &p; cout << "z = " << (objectPointerToP->z); return 0; }
7th Apr 2021, 8:28 PM
Josh Greig
Josh Greig - avatar