Take the 2-minute tour ×

Is there any difference between

foo(int* arr) {}


foo(int arr[]){} ?


share|improve this question
Wow -- lots of Questions of this type today!! –  al-Acme Mar 30 '11 at 20:30
Related, but newer, question: stackoverflow.com/questions/5573310/… –  jogojapan May 25 '13 at 9:34

4 Answers 4

up vote 9 down vote accepted

No, there is no difference between the two.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

You will have to dereference values to the first one...

share|improve this answer
i ....... think –  Martin Milan Mar 30 '11 at 20:19
nope. well it depends, you can dereference the second one if you want: *(array + 3) is the same as pointer[3]. –  BlackBear Mar 30 '11 at 20:21
Well, I have two functions: int function(int arr[]); int function2(int* arr); For testing, I have this array: int arr[5] = {1,1,1,1,1}; In Visual Studio 2010 I can do this: function(arr); function2(arr); Even though I didn't pass in a dynamically allocated array into function2, it still allowed me to do it. Why is this? And from doing benchmarks, both functions have identical results, so if dereferencing does happen, it's negligible. –  leetNightshade Mar 30 '11 at 20:26
You can even write 1[arr] for both! –  Flexo Mar 30 '11 at 20:37
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. –  Linus Kleen Nov 13 '12 at 20:10

Your Answer


