Are the 2 following functions essentially the same function?
ie, is an int* exactly the same as a int[]?
int myFunction(int* xVals, int* yVals, int nVertices);
int myFunction(int xVals[], int yVals[], int nVertices);
How can I use the 1st function? Ie, how can I pass arrays in the parameters? Is the following valid/correct?
int xVals[5], yVals[5], zVals[5];
myFunction(xVals, yVals, zVals, 5);
// or should it be..
myFunction(&xVals[0], &yVals[0], &zVals[0], 5);
In a function parameter list, then the function declarations are equivalent:
However, this does not readily generalize. Inside a function, there is a big difference between:
And in a function interface, there’s a big difference between the two parameter types:
You also ask about (corrected):
These calls are both valid and are equivalent to each other.
The answer to your original headline question ‘Is an
int *exactly the same as anint []?‘ is No.There are a very limited number of circumstances under which they are equivalent, but there are many more circumstances where they are very different.
The answer to your revised headline question ‘Is an
int *parameter exactly the same as anint []parameter?‘ is Yes!