Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is the most readable way of using address of an array element? I usually see &array[n] but I personally think array+n looks cleaner and more readable.
What do other C coders prefer?

share|improve this question

closed as primarily opinion-based by gnat, MichaelT, GlenH7, Ampt, Dan Pichelman Jul 7 at 14:02

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

Go with whatever your coding standards say. –  ChrisF Apr 27 '11 at 12:46
I like &n[array] myself. –  David Schwartz Aug 18 '11 at 23:34
add comment

2 Answers

up vote 1 down vote accepted

IMHO "address of an array element", when written in C, turns into &array[n]: since & is the address-of operator and array[n] is usually an array element, this seems to follow quite naturally from the language used in the question.

P.S. For those that also use other languages, this has the added benefit of also working with e.g. C++ std::vectors or D's arrays.

share|improve this answer
add comment

If it is not nailed down by the coding standards, then I prefer to use &array[n] as I find I am ...

  1. more likely to understand the intent at a later time.
  2. less likely to make a pointer arithmetic goof.

Hope this helps.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.