A question about arrays and valid pointers

Discussion in 'C Programming' started by Tony Johansson, Aug 26, 2003.

  1. 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
     
    Tony Johansson, Aug 26, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Johansson

    A question about arrays and valid pointers

    Tony Johansson, Aug 26, 2003, in forum: C Programming
    Replies:
    5
    Views:
    356
    Glen Herrmannsfeldt
    Aug 28, 2003
  2. kelvSYC

    Arrays and Pointers to Arrays

    kelvSYC, Sep 26, 2003, in forum: C Programming
    Replies:
    2
    Views:
    403
  3. Replies:
    1
    Views:
    678
    -berlin.de
    Mar 28, 2005
  4. Philipp
    Replies:
    21
    Views:
    1,181
    Philipp
    Jan 20, 2009
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    729
Loading...

Share This Page