GATE CSE
First time here? Checkout the FAQ!
x
0 votes
101 views

Answer is 407 , how? Please dont just throw away formula, explain it.

asked in Programming by Active (2.2k points)   | 101 views

3 Answers

+4 votes
Best answer

No formula used.

This requires just counting of numbers.See the below diagram

Each element requires 2B.

Like A[0][0] =351-352 ,A[0][1]=353-354.......

This is given to have a idea on how elements are stored and not beneficial when in big size is given.

answered by Veteran (11.4k points)  
selected by
+4 votes
Given array is Table[6][8] means the dimension of the 2D array is 6 rows * 8 columns

Desired location of table[3][4] means a element which is available in 4th row .

and in 4th row it is present at 5th coulmn .

so for reaching the 4th row , you have to cross the all elements present in 3 rows so = 3*8(bcoz 8 element will be present in one row )

and in 4th row for reaching the 5th column element you have to cross the previous 4 element present in 4th row .

so element need to be cross in 4th row =4

so total element need to be crossed = 3*8+4 =28 elements

consider size of int is 2 bytes . so bytes need to skipped = 28*2 =56 bytes

as given base address of 2D array is 351 . so from 351 we need to move 56 bytes ahead = 351+56 =407

so 407 is the address of table[3][4] .
answered by Loyal (3.4k points)  
+2 votes
we have to find TABLE[3][4]

according to given data number of columns in array=8

Number of rows before TABLE[3][4] = 3 ( 0th row, 1st row, 2nd row )

so elements in this 3 rows = 3 * 8 = 24

now number of columns before TABLE[3][4] = 4 ( 0,1,2,3 )

so total elements before TABLE[3][4] = 24+4

So location = 351 + 28*2 =407. I have assumed size of int as 2 bytes
answered by Boss (7.7k points)  


Top Users Mar 2017
  1. rude

    4018 Points

  2. sh!va

    2994 Points

  3. Rahul Jain25

    2804 Points

  4. Kapil

    2608 Points

  5. Debashish Deka

    2104 Points

  6. 2018

    1414 Points

  7. Vignesh Sekar

    1336 Points

  8. Bikram

    1218 Points

  9. Akriti sood

    1186 Points

  10. Sanjay Sharma

    1016 Points

Monthly Topper: Rs. 500 gift card

21,446 questions
26,759 answers
60,943 comments
22,955 users