Re: Passing pointer to array of structs

On Tue, 25 Mar 2008 19:21:57 +0300, "Vladimir Grigoriev"
<> wrote:

"Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx> wrote in message
goodTweetieBird wrote:
int main()
int a[10] = {1,2,3,4,5,6,7,8,9,10};

For arrays foo( &a ) is equivalent for foo( a ).

In value but not in type. Above, the type of &a is int(*)[10], and assuming
the function foo is declared foo(int*), the "a" in foo(a) undergoes the
array to pointer conversion resulting in a pointer to a's first element of
the type int*. In English, these types are "pointer to an array of 10 ints"
and "pointer to an int", respectively. To see the difference, consider what
it means to increment them.

The difference exists only
if 'a' was declared as a pointer to an array not array itself.
For example

char a[2] = "A";
char * a = "A";
In the second case foo( &a ) and foo( a ) are different!

Rigorously speaking, there is no "pointer to an array" in what you wrote
above. As I explained earlier, the difference in the first case is in the
types of the expressions, while the difference in the second case applies
to values as well as types.

Doug Harrison
Visual C++ MVP