When you leave off the parentheses, the effect is the same as the former
That's backward, actually:
Code:
int (*array)[5]; /* this is a pointer to an array */
int *array[5]; /* this is an array of pointers */
int *(array[5]); /* this is also an array of pointers */
To d3m105: Your code as posted is not correct. You're calling InitStructs() before you give the prototype; don't do that, because prototypes allow your compiler to do type-checking on function calls.
If you do this:
Code:
struct Test { int a; };
void InitStructs(struct Test * myStructs[5]); /* this is a prototype */
int main(void)
{
struct Test myStructs[5];
InitStructs(&myStructs);
return 0;
}
void InitStructs(struct Test * myStructs[5]) {}
Your compiler should tell you that you're passing the wrong type. Always, always use prototypes for your functions.
To get this working, use something like this:
Code:
struct Test { int a; };
void InitStructs(struct Test myStructs[]);
int main(void)
{
struct Test myStructs[5];
InitStructs(myStructs);
return 0;
}
void InitStructs(struct Test myStructs[]) {}
If you really want to pass a pointer to the array by using &myStructs (which you almost surely don't except as an academic exercise) it's slightly more complex. I'd rather not type yet another block unless you have a real interest in seeing how pointers to arrays work.
The method I showed you above is about as close to transparent pass by reference you'll find in C. It's really not pass by reference, but inside your InitStructs() function you can treat myStructs like an array of struct, for the most part.