I was trying to dig more into using arrays and pointers while I came across this problem:
main.cpp:13:7: error: cannot convert 'int [2][5][10]' to 'int*'
in assignment show=ary;
Here's the code:
#include <iostream>
using namespace std;
void arrayLearn(int *);
int main()
{
int ary[2][5][10];
int *show;
ary[2][4][9]=263;
ary[2][5][10]=100;
show=ary; //line 13
arrayLearn(show); //line 14
cout <<"End process"<<endl;
return 0;
}
void arrayLearn(int *arg)
{
for(int i=0;i<100;i++)
{
cout<<"Pointer position: "<<i<<" Value: "<<*(arg++)<<endl;
}
}
If I remove the line 13 and replace line 14 with the following code,
arrayLearn(ary[5][10]);
then the program compiles, but I don't understand why I should pass only two dimensions and not three. If I'm passing the pointer to the first item in the array then why can't I just pass the pointer like this?
arrayLearn(ary);
Please let me know if I've missed some vital concepts or failed to see a really simple mistake.