int a[17];
size_t n = sizeof(a) / sizeof(int);
In C it is most common to find a length of an array like this and it is pretty clear. My question though is that the following wouldn't work:
int days[] = {1,2,3,4,5};
int *ptr = days;
size_t n = sizeof(ptr) / sizeof(int);
What I suppose is happening here is that ptr is just a normal 8-byte address pointing to the first element of the array, so it won't give us the real length of the array. But in the first example, sizeof(a), a is also just a pointer pointing to the first element of the array. So what is the difference here and why does one work but the other not?