PSXDEV snippets : Array vs Pointer
Question
In C, not sure about the syntax to have a pointer to a double(2d?) array as a function argument ? (If that's even possible). Here's some pseudocode that might help understand the question:
int myarray[2][8];
void dostufftoarraycontent(int * myarray){
printf("%d",myarray[0][0]);
printf("%d",myarray[1][7]);
}
Specifically, should I use
int * myarray
,int * myarray[]
,int * myarray[2][8]
... ?
Answer
Nicolas Noble : basically, your 2d array here is just a syntax sugar for a 1d array
sickle : oh this kinda makes sense now since what you said about
blah[y]
being the same as
*(blah + y)
so withblah[x][y]
instead ofx
incrementing the pointer byx
, it's
( x * sizeof(subarray) )
like :
*( x*sizeof(subarray) + y*(sizeof(y)) + blah)
Sources
Nic & Sickle - https://discord.com/channels/642647820683444236/642849069378568192/830119808912719882