943,967 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3983
  • C++ RSS
Dec 7th, 2005
0

2d address calculation

Expand Post »
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).
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sahil_logic is offline Offline
31 posts
since Nov 2005
Dec 7th, 2005
0

Re: 2d address calculation

SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Dec 7th, 2005
0

Re: 2d address calculation

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
C++ Syntax (Toggle Plain Text)
  1. int *p = array + ((row_numer-1) * NumColumns)
C++ Syntax (Toggle Plain Text)
  1. int array[2][5];
  2. // set a pointer at the beginning of row 2
  3. int* ptr = (int*)array + (1*5);
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: recursive linked list
Next Thread in C++ Forum Timeline: Easy Polymorphism Q Part 2 :)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC