# calculating an address of an array element

Page 1 of 1

## 2 Replies - 2535 Views - Last Post: 24 September 2007 - 04:41 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=33871&amp;s=20946e34a626201f174e26643c1ee7e3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 abdullateef

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

# calculating an address of an array element

Posted 23 September 2007 - 07:13 PM

hi everyone
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

• system("revolution");

Reputation: 53
• Posts: 2,335
• 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>

### #3 1lacca

• code.rascal

Reputation: 44
• 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.