I'm trying to figure out the size of an array in C.
My first implementation was based off of the accepted answer to this question:
int size = sizeof(arr)/sizeof(arr[0]);
But that always gave me one. I tried just doing:
int size = sizeof(arr);
And this gives me 4 every time, regardless of the size of the array.
Here's a minimal example of the code I used.
void findSize(int arr[]) {
int size = sizeof(arr);
printf("%d\n",size);
}
int main(int argc, char** argv) {
int arr[] = {4,6,9,2,6,3,7,2,5,1,2};
findSize(arr);
}
Regardless of the array I use, this code always prints 4.
Why is it printing 4, and how do I find the actual size of the array?