Hello ladies and gents,
I was trying to write a small example of a pointer to a two dimensional array like this after looking up how to write the syntax at Narue's Et.Conf. world like this:
#include <iostream>
#include <iomanip>
void array(short (*myArray)[4][4]);
using namespace std;
int main()
{
short Map[4][4] = {0};
short (*pMap)[4][4] = ⤅
array(pMap);
cout << "Press enter to exit\n";
cin.ignore(cin.rdbuf()->in_avail() + 1);
return 0;
}
void array(short (*myArray)[4][4])
{
short size = sizeof myArray[0]/ sizeof myArray[0][0];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
{
cout << (*myArray)[i][j] << " ";
if (j%4 == 3) cout << endl;
}
}
Works like a charm, though, when I wrote *myArray[j] instead of (*myArray)[j], the output was that the first row was all 0, but the rest were random numbers :-|
Can someone tell me why this happens :?:
Thanks for the help,