The
dispNumbs
is not an
int
. It is an
array of integers. However, on line 25, when you do call a function with dispNumbs as parameter the compiler states that it is a pointer to int (
int*
). How can that be?
An array is not a pointer either. They are different types. However, there is an implicit conversion from array to pointer; array
decays to pointer.
The size of an array is known at compile-time. A pointer does not know whether it points to zero, one or array member of valid objects. Hence "decay" as in "lose something".
Function arguments are
by value (by default); they are copies of values that the function is called with. An array can be large. To copy array can thus be relatively expensive. The designer's of C chose that there are no "by value array function arguments". They chose that a pointer is used instead. It is a by value argument, but what is copied is the address of the first element of the array. Due to the decay you have to pass the array size as separate function argument.
While the argument type in reality is a pointer
void fileDump(int *, int)
one can use the bracket syntax
void fileDump(int [], int)
too to hint that
the function operates on array.
Both arrays and pointers are dereferenced. Again, the syntax is interchangeable:
1 2 3 4 5 6 7 8 9 10
|
*(foo + n)
// is same as
foo[n]
// and
foo[0]
// is same as
*(foo + 0)
// is same as
*foo
|