Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Array help in C++ (Not looking for direct answers)

    I'll admit this is homework, but I do not desire a direct answer for my question, rather some sort of reference to learning material that can guide me.

    Code:
    int fib[] = { "values hidden to prevent people giving me direct answer" };
    Array is stored on a 32-bit machine, at memory address "value hidden" (hexadecimal). What are the values of the following expressions?
    fib *fib &fib[0] &fib[6] *(fib+7)

    I missed the day he covered this, and apparently he covered this on the whiteboard, so no electronic record of that session anywhere. So I need to learn what these array operations do.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You'll want to get familiar with pointer arithmetic. An array points to the location in memory where the first value is stored and then each value in that array is offset in memory by the size of the datatype being stored. You can find the 5th element in that array by either using the array index array[5] or an offset to the array pointer *(array + 5). Make sense? You also want to get familiar with dereferencing pointers *array as well as using address of pointers &array.

    Searching on "pointer arithmetic array" should get you on the right track.
    One site to start with
    http://www.eskimo.com/~scs/cclass/notes/sx10b.html
    Last edited by Spookster; 10-23-2013 at 11:28 PM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • Users who have thanked Spookster for this post:

    Reaga (10-23-2013)

  • #3
    New Coder
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks, I'd just been searching Array operations. That seems much more likely.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •