Selection_sort function

when i am trying to get the size of the array in the selection_sort function using sizeof( ) operator ,
i got the answer 8 every time ,why?

array parameters are treated as pointers.
So the expression sizeof(arr)/sizeof(arr[0]) becomes sizeof(int *)/sizeof(int) which results according to size of int(depend on machine) and irrespective of the size of the array.

Therefore, sizeof() should not be used to get number of elements in such cases. A separate parameter for array size (or length) should be passed to fun().

I didn’t get you.

We know that array stores the address of the first element(so basically it is the pointer variable) . Here also in main function , sizeof(arr)/sizeof(arr[0]) becomes sizeof(int*)/sizeof(int) but it works fine here, why?

as arr is define in main
so there(in main() ) it is not pointer it is an array
hence give desired output

if you define a array in any function also there it will give output accordingly

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.