Last Updated : 05 Nov, 2018

Consider a character 2D array A of 5 rows and 5 columns. If this array is stored in the lower triangular matrix fashion then find the location of a[17][16].
The base address is 10000. lower bound (lb1) = lower bound (lb2)= 14 and upper bound(ub1) = upper bound(ub2) = 18
(A) 1016
(B) 1008
(C) 10008
(D) 10016


Answer: (C)

Explanation: Loc([i][j]) = Base address + [(i – lb1)*(i – lb1 + 1) / 2 + (j – lb2)] * size of each cell.
Since the array is a character array every cell will take 1 byte.
A[17][16] = 10000 + [( 17 – 14 ) * (17 – 14 + 1) / 2 + (16 – 14)] * 1
= 10008
So, option (C) is correct.

Quiz of this Question


Share your thoughts in the comments