This is an interview question:
What is difference between int []
and int*
, all of them are input arguments to a function.
f(int a[] , int* b)
My answers:
For f()
, they have the same functions. The first one is the beginning position of the first element in a[]
.
The second one points to an int
.
But, how to distinguish them from each other without passing other arguments ?
As function parameters, the two types are exactly the same, int []
is rewritten to int *
, and you can't distinguish between them. Many many questions in StackOverflow cover this subject, and the c-faq even has a special section on pointer and arrays (as arguments or not). Take a look into it.
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