I'm trying to access the elements of a multidimensional array with a pointer in C++:
#include<iostream>
int main() {
int ia[3][4] = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}
};
int (*pia)[4] = &ia[1];
std::cout << *pia[0]
<< *pia[1]
<< *pia[2]
<< *pia[3]
<< std::endl;
return 0;
}
I'm expecting *pia to be the second array in ia and therefore the output to be 4567.
However the output is 4814197056, so I'm obviously doing it wrong. How do I the access the elements in the rows correctly?
int * pia = ia[1];std::cout << pia[0];