VextoR
VextoR

Reputation: 5185

any difference between foo(int* arr) and foo(int arr[])?

Is there any difference between

foo(int* arr) {}

and

foo(int arr[]){} ?

Thanks

Upvotes: 6

Views: 1805

Answers (4)

anatolyg
anatolyg

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

Julio Guerra
Julio Guerra

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

Martin Milan
Martin Milan

Reputation: 6390

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

Upvotes: -2

James McNellis
James McNellis

Reputation: 355387

No, there is no difference between the two.

Upvotes: 12

Related Questions