Because array decays to a pointer when you pass it into a function as an argument. And so the sizeof(array)
will not give you the size of the array, but the size of the pointer.
You can either have the array size as an extra argument
, or pass the array as a reference
so that sizeof(array) will give you the correct size. (Detailed here: What is array decaying?)