int narr[4] = {0}; int *pnarr = narr; printf("size of pnarr:%d and *pnarr:%d\n", sizeof(pnarr), sizeof(*pnarr)); The sizeof(pnarr) return the pointer type size. But the sizeof(*pnarr) return the int type size. Why?
Does the pnarr point at the first element of narr, so I cannot get the array length by pnarr?
How can I get the array length by pointer?
Here is the code of get array length by pointer. Is it right?
int arr_len(int *arr) { int len = 0; while (*arr) { arr++; len++; } return len; }