Pointers to array of pointers in c -
can please explain me difference between 2 following declarations:
char (*arr_a)[5]; char arr_b[20]; and why:
sizeof (*arr_b) = sizeof (char) sizeof (*arr_a) = 5*sizeof(char)
char (*arr_a)[5]; declares pointer 5-element array of char.
char arr_b[20]; declares 20-element array of char.
so, output of
sizeof (*arr_a) should straight forward -- dereferencing pointer array yields array , it's size 5.
the following:
sizeof (*arr_b) gives 1, because dereferencing identifier of array yields first element of array, of type char.
one thing need know understand how array evaluates in expression:
in most contexts, array evaluates pointer first element. example case when apply indexing array.
a[i]synonymous*(a+i). array evaluates pointer, works expected.there exceptions, notably
sizeof, gives storage size of array itself. also,_alignof,&don't treat array pointer.
Comments
Post a Comment