In order to understand how pointer work I wrote this function which has to return a 3*3 matrix.
int** Matrix::getMatrix(){
cout<<"The matrix is: \n";
int (*p)[3]=m;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<m[i][j]<<"\t";
}
cout<<"\n";
}
return p;
}
Here m
is a 3*3 array.But at the line return p;
it gives the error return value type does not match function type
.
With p am I not returning a pointer to a 3*3 matrix.?What's wrong with this.Can someone please help me to correct this.