c++ - Pointers to multidimensional arrays -
this question has answer here:
what difference between
int *p1[m][n]
and
int (*p2)[m][n]
also if define such pointer
int (*p3)[m][n][k]
what represent? if can explain differences between above three, helpful.
it helps know can read c declaration using alternating right-and-left fashion. direct answer question is:
int *p1[m][n]
array of arrays of pointers-to-ints. int (*p2)[m][n]
pointer array of arrays of ints. int (*p3)[m][n][k]
pointer array of arrays of arrays of integers.
you can think of these using standard "2d" or "3d" terminology, 2d array table first set of brackets indicating row , second set of brackets indicating column. not 100% faithful way computer works, it's highly effective mental model. going how decipher complicated c declarations:
you read them boustrophedonically, first right, left, right, left, , on. here's example.
int * const (*p[30])(int x)
we start @ name being declared, p. right size of p, 30.
so know p array of 30 something. left, , find *, know p array of 30 pointers something. right, , find parentheses, indicating function. know p array of pointers functions. can trivially include parameters these functions should int x.
so we've run out of things on right, keep interpreting left elements.
p array of pointers functions returning... const. there's more on left, keep going. p array of pointers functions returning const pointers int.
Comments
Post a Comment