Reputation: 75
In many code examples I find, they use "&Array[0]" if an array has to be passed to a function. Is there any reason to do so ? They could simply write "Array".
Upvotes: 1
Views: 84
Reputation: 5683
This is a pure style issue, and you should just do whatever your dev team prefers. Personally I like to use plain old Array
and if I want to offset by n
elements I would do Array + n
. But some people find that confusing and use &Array[n]
, even when n == 0
.
In defense of the other side the Array + n
syntax requires you to know more about C in order to understand it. It involves both arrays degenerating into pointers, and also pointer arithmetic. But in my view, C programmers need to know all that stuff anyway, it's not a complicated language.
Upvotes: 4