Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

Is there any difference between

foo(int* arr) {}

and

foo(int arr[]){} ?

Thanks

like image 863
VextoR Avatar asked Mar 30 '11 20:03

VextoR


People also ask

What is the difference between arr [] and * arr?

It will have the type int . Since the function expects a pointer (when declaring an argument, int arr[] is equal to int* arr ), passing plain arr will work fine, but arr[i] will get a complaint from the compiler since you pass something of the wrong type.

Is int arr [] and int * arr the same?

No difference. At all. In a function parameter list, int arr[] is nothing but an "alternative" writing for int* arr .

What does this mean int * arr?

int * arr[] = { m[0], m[1], m[2] }; This defines an array of pointer to int , with its number of elements being determined by the number of elements in its initialiser. In the above example arr will have three elements. Variable definition inside a function's parameter list.

Are arr and &arr same?

arr is an integer pointer (int*) which points the first element of the array. &arr is an integer array pointer (int*)[5] which points the whole array. (all five elements.) &arr is a pointer to an entire array.


1 Answers

No, there is no difference between the two.

like image 79
James McNellis Avatar answered Sep 22 '22 13:09

James McNellis