"Douglas" <mm***@yahoo.co.uk> wrote in message
news:4c**************************@posting.google.c om...
Hi,
What is the need for the inaccessible pointer address beyond the end of an
array?
It's sometimes convenient when iterating through an array.
But be sure not to try to dereference it.
Eg. could
for(ip = &array[0]; ip < &array[arraySize]; ip++)....
not be rewritten as
arraySize--;
for(ip = &array[0]; ip <= & array[arraySize]; ip++)....
Yes, it could also be written e.g.:
for(ip = &array[0]; ip <= & array[arraySize - 1]; ip++)....
However the first form above is the most 'idomatic'
(i.e. most quickly recognized by most C coders).
Use whichever form most clearly expresses your intent.
I don't like your second form, because if possible,
I'd declare 'arraySize' as 'const' (typically it would
be a function parameter), in which case the expression
'arraySize--' would not be allowed.
Personally, if I'm using an array's size as my
'boundary condition' (as opposed to using an array
element value, such as a string terminator), I'll use
indices rather than pointers, e.g.:
size_t i = 0
for(i = 0; i < arraySize; ++i)
/* etc */
-Mike