2d address calculation

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2005
Posts: 31
Reputation: sahil_logic is an unknown quantity at this point 
Solved Threads: 0
sahil_logic sahil_logic is offline Offline
Light Poster

2d address calculation

 
0
  #1
Dec 7th, 2005
plz give me links or discuss on address calculation in 2d arrays.
i have little knowledge of calculating the address. can any one give some formula or something coz my professor gave it but i wasnt able to follow . i remember he was using terms like rowmajor, column major, lower base , upper base etc.
so if any one is having knowledge plz help as this topic is not even in the book that i am using ( the course book i mean).
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: 2d address calculation

 
0
  #2
Dec 7th, 2005
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: 2d address calculation

 
0
  #3
Dec 7th, 2005
In C and C++, arrays are stored in memory by row. That is, all the columns of the first row appear first, then all the columns of the second row, etc. If you have an int array with 2 rows and 5 columns then the location of any given row can be caluculated by this formula
  1. int *p = array + ((row_numer-1) * NumColumns)
  1. int array[2][5];
  2. // set a pointer at the beginning of row 2
  3. int* ptr = (int*)array + (1*5);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC