T
Tony Johansson
Hello experts!
I question about understanding. I have read a book that says.
If you have an array of integers you know that one element past the end of
the array is legal as address but not to follow. That's ok.
The address to one element past the end of the array is also grater then the
address to the last element.That's also ok.
The book says " Don't assume that a pointer to the element just before the
start of an array is legal.
This for loop should be valid as I think but the book say no because this
for loop has a problem:
the loop terminates only when ptr becomes less then a. And that's not
guaranteed to be a legal address, which means the comparasion may fail.
for (ptr = &a[num-1]; ptr >= a; ptr--)
printf("%i\n", *ptr);
I think, don't you that the address to the element just before the start of
an array must be lower then the address to the first element.
//Tony
I question about understanding. I have read a book that says.
If you have an array of integers you know that one element past the end of
the array is legal as address but not to follow. That's ok.
The address to one element past the end of the array is also grater then the
address to the last element.That's also ok.
The book says " Don't assume that a pointer to the element just before the
start of an array is legal.
This for loop should be valid as I think but the book say no because this
for loop has a problem:
the loop terminates only when ptr becomes less then a. And that's not
guaranteed to be a legal address, which means the comparasion may fail.
for (ptr = &a[num-1]; ptr >= a; ptr--)
printf("%i\n", *ptr);
I think, don't you that the address to the element just before the start of
an array must be lower then the address to the first element.
//Tony