I mean the latter allows us to get the number of elements in the array using sizeof()
something which isn't possible in the first one.
No, that's not possible for the latter, too. Here is a misunderstanding of yours. Both notations are absolutely equivalent as function parameter and denote a pointer. arr[]
does not denote an array nor a pointer to an array explicitly.
Take a look at here:
C pointer notation compared to array notation: When passing to function
You can only get the size of the array if you use sizeof()
at the array name itself inside of the scope the array is visible or pass another argument/parameter to the function which contains the information about the size of an array from the previous sizeof()
use.
You cannot use sizeof()
at a pointer to an array to get the array size, neither in the function where the array is declared nor in another.
But why we every need to use the first one?
To simple symbolize that it is a single pointer and not an array as this confusion in fact already brought you to here. :-)