I played with pointers to help better understand. I declared aas a pointer to an array of integers of length 3 and bas an array of integers of length 3. Then I point ato b.
int main()
{
int (*a)[3];
int b[3] { 2, 4, 6 };
a = &b;
a[0][0] = 8;
std::cout << a[0][0] << "\t" << b[0];
std::cout << a[0] << "\t" << b[0];
return 0;
}
To access an element bthrough a pointer a, I need to do a[0][0]as if they were an array of arrays. This compares to declaring a pointer to an array of integers using a new keyword, where I can simply output c[0].
int* c = new int[3] { 2, 4, 6 };
std::cout << c[0];
Why is this?
Thank you very much george
user2406944
source
share