Hello All:
I have a question about how something works with respect to passing an array to a function. First a quick code example:
Code:
void cat (int dataA[])
{
//...
}
void dog (int dataB[3])
{
//...
}
int main ()
{
int x[10] = {11, 13, 15, 17, 19, 21, 23, 25};
cat(x);
dog(x);
return 0;
}
I'm trying to understand some of the details concerning what the int [] as a function parameter really means and how it relates to a pointer.
1) As a function parameter, what exactly does int dataA[] mean and how does it relate to something like int* dataA? sizeof(dataA) in both cases returns 4. However, if one declares an static local array in a function such as int moo[] = {1, 2, 3}; then sizeof(moo) returns 12. So there must be some difference between int dataA[] and int moo[].
2)With dataA of function cat (and dataB in function dog), it is possible to increment them as in dataA++; or dataB++; ... This would lead me to think that even though the parameters are declared as something that looks like an array declaration, the compiler actually is just treating them like int*... Am I missing something?
3)If you do put a number in the [] of a function parameter array, is it used for anything? Does it have any implications? Doesn't seem to matter when sending a 10 element array to dog. Still compiles and executes with no apparent problems. (BTW - i know this shouldn't be done, but i'm still curious of what's going on).
4) can you suggest some reading material that would specifically address some of these issues? I'm finding a ton of references about "what to do" and "what not to do" (don't put number in [] of function parameters), but not a great deal of "why". Any suggestions would be appreciated.
Thanks
-txcs