The rule that I have always found useful is โinside out, from right to leftโ:
char *(*arr)[2];
So, inside the paren group first has "* arr", from right to left, "arr is a pointer"
nothing remained in parens, so "arr is a pointer" to the rest, from right to left: an array of two pointers to char.
A similarly short rule, which has always been useful, is to say that "the value of the C array is a pointer to its first element", which also emphasizes the difference between using the name for its value and for other attributes: f(arr)
and arr+1
use the value arr
, and its value in each of them is a pointer to its first element (with its delimiter and restrictions), but, for example, sizeof arr
does not evaluate and therefore gives the size of the array.
source share