Reputation: 5185
Is there any difference between
foo(int* arr) {}
and
foo(int arr[]){}
?
Thanks
Upvotes: 6
Views: 1805
Reputation: 28320
There is no difference for the C compiler. There is a difference for the programmer that reads the code though.
Here, arr is a pointer to an integer (possibly for returning the result from the function):
foo(int* arr) {}
Here, arr is a pointer to the first integer in an array (possibly for passing a list of numbers in and/or out of the function):
foo(int arr[]) {}
Also, specifying the return type of the function would help.
Upvotes: 5
Reputation: 5661
The semantic is the same, but for an external programmer, it is easier and immediate to understand: the second function takes an array as argument. It could not be as immediate for the first one.
Upvotes: 1