I passed a array to function and tried to find the length of the array . but the result was not expected . can anybody explain please?
int main()
{
int arra
You have to remember that arrays decays to pointers. That means that in the function func
the variable arr
is not actually an array but a pointer. And doing sizeof
on a pointers returns the size of the pointer and not what it points to.
You get the result 2
because you're on a 64-bit system where pointers are 64 bits (i.e. 8 bytes), an when divided by the size of int
(which is 4 bytes) you get the result 2
.