I am new to c++ and trying to understand pointers. I read a example somewhere, which is like this:
#include<iostream>
#define N 5
using namespace std;
class Test {
int x, y;
public:
Test(int a, int b)
: x(a), y(b)
{
}
void print()
{
cout << x << " " << y << endl;
}
};
int main()
{
Test **arr = new Test*[N];
for (int i = 0; i < N; i++) {
arr[i] = new Test(i, i + 1);
}
for (int i = 0; i < N; i++) {
arr[i]->print();
}
}
So, in the line
Test **arr = new Test*[N];
as far as i understand, **arr
means that it's a pointer to a pointer which points to a object. So when we assign it to new Test*[N]
, does it means *arr
stores address of N object pointers?
And if it is correct, then how can i print the address of a object from the array of objects? let's say i want to print the address of the object Test[3]?