In main
, arr
is an array and sizeof
yields the size of the array.
In printArraySize
, arr
is a pointer to int
and sizeof
yields the size of the pointer to int
object.
In C you cannot pass (directly) arrays to functions, you can only pass a pointer to the first element of the array. To get the size of the array in printArraySize
you need to pass it explicitly as an argument to the function.
In C++ you can pass C arrays by reference but you shouldn't use C arrays in the first place but use std::array
or std::vector
instead.