Is there any difference between
foo(int* arr) {}
and
foo(int arr[]){}
?
Thanks
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.
No difference. At all. In a function parameter list, int arr[] is nothing but an "alternative" writing for 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.
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.
No, there is no difference between the two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With