I am reading about the address calculation formulas for one and two-dimensional arrays. I have two related doubts concerning it.
In one of the problems, we are asked to calculate the location of B [1700] for an array B [1300....1900]. Now, I understand that B [1700] is actually the 401th element in the array (correct?), so we can calculate its address.
But in another problem, we are given an array X [-15....10,15.....40] and are asked to determine the location of X [15][20] but I don't see how it is even a part of the array since the "row" subscript(i.e. 15) is not contained in (-15....10). (According to me the last element of this array is X [10][40]).
My second doubt is: In another question, we are given the array M[-3......18,-8......7] (stored column-wise where width of element = 8 bytes) and are asked to calculate the base address given that the address of element M [5][10]=4000.
The solution proceeds as -
M [5][10] = BA + W*(M*(j-Lc)+(i-Lr)) therefore, M [5][10]=4000 + 8*(22*(10-0)+(5-0))
i.e. my book answer takes Lc = 0 & Lr = 0 but I think it should be Lc = -8 and Lr = -3? So, which is it? Also can I write a program in which I can verify this for myself (specifically, how can I declare an array in c++ whose subscript doesn't start at 0?)? Thank you so much.