Well, there are several ways to pass an array to work. You can pass it with a pointer by reference, and there are ways to determine whether or not to determine its size explicitly for both methods.
In your question, you are comparing these two ways:
- Pointer to the first element:
void f(int *arr)
- Link to the entire array:
void f(int (&arr)[size])
You ask why you need to specify the size in only one of these cases.
It sounds like you think the only difference between the two is that one uses a pointer and the other uses a link. But this statement is wrong, they have more differences: one is a pointer to the first element, and the second is a link to the entire array.
You can pass an array with a pointer to the entire array:
void f(int (*arr)[size])
Compare this with your example with passing refence to the whole array:
void f(int (&arr)[size])
They are similar, they have similar syntax, they both explicitly determine the size of the array.
Also consider the following:
void f(int &arr)
It is like passing a single int by reference, but you can pass an array of unknown size to it.
Alternative pointer to it
void f(int *arr)
You ask why you need to specify the size of the array in only one of these cases. This is because of the syntax you used, not because it is a pointer and the other is a link.
As I said, you can use a pointer or a link. And you can specify the size of the array, or you can allow the use of an array of any size. These two are not connected.
// by pointer by reference /* Any size */ void f(int *arr) void f(int &arr) /* Specific size */ void f(int (*arr)[x]) void f(int (&arr)[x])