Welcome, Guest. Please login or register.

Author Topic: Finding the address of an array element  (Read 8778 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline holbromf

  • Newbie
  • *
  • Join Date: Jul 2002
  • Posts: 9
    • Show all replies
Re: Finding the address of an array element
« on: March 14, 2003, 03:11:37 PM »
Hi,
      The important idea here is the data being contiguous in memory. This is not guaranteed.

For example: int data[20][4] give us an array of 20 pointers addressed at &data or 'data' in C. Each of these pointers  is to an array of 4 integers. These integer arrays may not be contiguous in memory where one array would lead onto another. Hence a formula for the address of an element would be unreliable. This would apply whether 'data' was declared on the heap i.e. with file scope or on the stack i.e. with function scope.
A reliable technique is to declare a single array in C such as data[big] and then using formulas to find addresses in this space.

                                                              Cheers Mike