I have a 3×3 array that I’m trying to create a pointer to and I keep getting this array, what gives?
How do I have to define the pointer? I’ve tried every combination of [] and *.
Is it possible to do this?
int tempSec[3][3];
int* pTemp = tempSec;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do
int *pTemp = &tempSec[0][0];If you want to treat a 3×3 array as an int*, you should probably declare it as an
int[9], and usetempSec[3*x+y]instead oftempSec[x][y].Alternatively, perhaps what you wanted was
int (*pTemp)[3] = tempSec? That would then be a pointer to the first element of tempSec, that first element itself being an array.You can in fact take a pointer to a 2D array:
You’d then use it like this:
That’s almost certainly not what you want, but in your comment you did ask for it…