I'm learning C++ syntax and I got to the point where I'm looking into arrays. I would like to ask you a question but first let me recap so I know that I got this stuff straight. I know that you can define a variable as an array with the following syntax:
<base type> name [<size(constexpr)>]
(the size being part of the type of the array). This would give me an array of size elements of base type If I wanted an array of pointers to the base type I could just add a * after the base type specifier as in normal pointer declaration.
<base type> *name [<size(constexpr)>]
I can't define an array of references because aray are supposed to hold only objects ( and references are just aliases).
Now, if I wanted to declare a reference or a pointer to an array I could use this syntax:
<base type> (&name) [<size(constexpr)>]
or
<base type> (*name) [<size(constexpr)>]
So far it is all clear. What I also know, is that I can pass an array as an argument to a function, but that call will always be interpreted as I am passing a pointer to the array's elements type. A function that is declared as follows:
void f(int array[10])
is the same as:
void f(int array[])
void f(int *p)
and whenever I call this function I am always passing a int* (passing by value).
Question:
what if I wanted to write the function prototype (a pure declaration) without using the parameter's name? I know that I can ordinarily omit parameter names in that case (I could write void f(int*)
but what about the other two declarations?).And more importantly, what if the parameter is a reference or a pointer to an array?
void f(int (&array)[])
or
void f(int (*array)[])
thanks!