Hi,
I was reading the C++ reference and ran across *(*(matrix + i) +j)
as a way to return data from a two index array (ie. matrix [i][j])
I'm trying to break it down to understand this notation better.
So I found *(matrix +1) is the same as (matrix +1). Basically the
address of the second set or row.
I would expect *(matrix +1) would be invalid or undefined since it to me
is dereferencing the entire second set or row of the multidimensional array.
Here is the program below:
Code:
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
float matrix [2][2] = { {0.8,0.9} , {4.1,3.9}};
cout << matrix << " address of matrix" << endl;
cout << (matrix + 1) << " matrix + 1" << endl;
cout << *(matrix + 1) << " *(matrix + 1)" << endl;
return 0;
}
The output is the same address for *(matrix + 1) and (matrix + 1)
Thanks