2 Replies - 2283 Views - Last Post: 24 September 2007 - 04:41 AM Rate Topic: -----

#1 abdullateef  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-September 07

calculating an address of an array element

Post icon  Posted 23 September 2007 - 07:13 PM

hi everyone
I wanna to ask about calculation of 2-D array address
I remember that equation that can do this

for an array, char a[R][C];

Address of an element a[N][M]; = baseAddress + elementSize * (N*C+ M);

Is it right?? :)

Other thing, is it deferent if the array is lower or upper triangular, or the same way by substituting missing elements by zeros??
e.g.

1 15 20
3 30
60

Any help I would appreciate :)

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: calculating an address of an array element

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: calculating an address of an array element

Posted 24 September 2007 - 04:03 AM

Hi I don't understand what is your question, can you explain a little better.
And welcome to </dream.in.code>
Was This Post Helpful? 0
  • +
  • -

#3 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: calculating an address of an array element

Posted 24 September 2007 - 04:41 AM

1)
Your formula seems to be correct.

2)
Depends on the definition of the triangular arrays.
If you define them by char a[R][C]; then yes, it is the same thing, since the elements are there, they are just not "used".
If you define the arrays to be truly triangular by allocating only the required space for the rows of the 2nd dimension, then the formula naturally won't work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1