2012-03-24 4 views
0

私はこの3-Dアレイ宣言有する:A[10..29][2..6][-1..0].行主要な3-Dアレイアドレス

であり、ベースアドレス100で始まる格納され、この行の主要な配列を仮定を要素A [25] [4] [ -1]が格納されているか? 私の答えは416

次の質問は 同じ仮定を使用して、どの要素が2000番地に格納されていますか?

どうすればこのような質問を解決できますか?

+1

これはどのような宣言ですか? '10..29、2..6、-1..0'?何か不足していますか? –

+0

これは完全な質問です: 次の3次元配列宣言を考えてみましょう:[10..29] [2..6] [ - 1..0]。 #配列の最初の10個の要素を、行優先順位で格納されていると仮定してリストします。 #カラムメジャーと同じです #各配列要素のサイズは20であると仮定して、全体の配列のサイズはどのくらいですか?私に正しい方程式を与えても、答えを出す必要はありません。 #この行メジャー配列はベースアドレス100から格納されていますが、要素A [25] [4] [ - 1]はどこに格納されていますか? #同じ仮定を使用して、どの要素が2000番地に格納されていますか? – nullException

答えて

0

これは役立つと思います。私はコードブロックに入れて、それがうまく並ぶようにしました。

/* 
* Assuming that the array is laid out row/column/other then... 
*  Row-major   Column-major 
*  A[10][2][-1]  A[10][2][-1] 
*  A[10][2][0]   A[10][2][0] 
*  A[10][3][-1]  A[11][2][-1] 
*  A[10][3][0]   A[11][2][0] 
*  A[10][4][-1]  A[12][2][-1] 
*  A[10][4][0]   A[12][2][0] 
*  A[10][5][-1]  A[13][2][-1] 
*  A[10][5][0]   A[13][2][0] 
*  A[10][6][-1]  A[14][2][-1] 
*  A[10][6][0]   A[14][2][0] 
* 
* Since the array is 20 rows (29 - 10 + 1) by 5 columns (6 - 2 + 1) by 
* 2 other (0 - (-1) + 1), with each elelment given as size 20, the 
* overall array size is 20 * 5 * 2 * 20 = 4000. 
* 
* The address of element A[25][4][-1], given the array is row-major 
* begining at 100 is... 
* Base address               100 
* Offset index0 = (25 - 10) * ((6 - 2 + 1) * (0 - (-1) + 1)) * 20 = 3,000 
* Offset index1 =     (4 - 2) * ((0 - (-1) + 1)) * 20 =  80 
* Offset index2 =        (-1 - (-1)) * 20 =  0 
* Offset for A[25][4][-1]           = 3,180 
* 
* Now that you have the idea, I will leave it to you to determine what element 
* is at address 2000. Here is a hint, repeat the above but using substraction. 
*/ 
関連する問題