Tell me more ×
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
2  
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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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