Question #239547

Consider a 20 *5 two-dimensional array marks which has its base address = 1000 and the size of an element = 2. Now compute the address of the element, marks[18][ 4] assuming that the elements are stored in row major order.


1
Expert's answer
2021-09-20T05:48:22-0400

Element A[18][0] is stored at

Base Address+18×2×5=1180Base\ Address + 18 \times 2\times 5 = 1180. which is 1000+18×2×5=11801000 + 18 \times 2\times 5 = 1180.

Therefore, marks[18][ 4] is stored at 1180+4×2=11881180 + 4 \times 2 = 1188

Answer is: 1188

The following program will give 1188 as the answer

#include<iostream>
using namespace std;
int main(){
	int sum = 1000;
	int arr[20][5];
	for(int i=0; i<20; i++){
		for(int j=0; j<5; j++){
			arr[i][j] = sum;
				sum = sum + 2;
				
		}
	
	
	}
	cout<<arr[18][4];
	//Answer is 1188
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Tanuj
10.10.23, 08:43

Thanks

LATEST TUTORIALS
APPROVED BY CLIENTS