See the comment section in the code. There I explained what I want to understand and what I know.
How I can get 28 using ptr. sizeof(arr) is giving me 28. (length of array elements) * sizeof(int) But I can't figure out how to get this value using ptr. I want this thing so I can get an array length using this method. In function own here.
int main (void)
{
int arr[7] = {5, 8, 10, 50, 55, 98, 354};
int result;
/* ------- From here ---------*/
int size = sizeof(arr) / sizeof(int); // sizeof(arr) = 28, sizeof(int) = 4. So size = 28/4 = 7
result = anyFunction (arr);
return 0;
}
int anyFunction (int array[])
{
int arraySize = sizeof(array) / sizeof(int); // this line
}
int *ptr = arr;
// Same as *ptr = &arr[0]
size = sizeof(ptr);
// 8 is the size of pointer.
size = sizeof(*ptr);
// size = 4. 4 is the size of arr[0]. Because its pointing to arr[0]. So its sizeof(arr[0]) or sizeof(5)