GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
132 views

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

asked in Programming by Active (2.3k points)   | 132 views

3 Answers

+6 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.9k 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.5k 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.9k points)  

Related questions

+1 vote
2 answers
2
asked in Programming by set2018 Loyal (3.6k points)   | 78 views
+3 votes
0 answers
3
asked in Programming by set2018 Loyal (3.6k points)   | 70 views


Top Users Sep 2017
  1. Habibkhan

    8312 Points

  2. Warrior

    2862 Points

  3. rishu_darkshadow

    2796 Points

  4. Arjun

    2766 Points

  5. A_i_$_h

    2526 Points

  6. manu00x

    2094 Points

  7. nikunj

    1980 Points

  8. Bikram

    1874 Points

  9. makhdoom ghaya

    1810 Points

  10. SiddharthMahapatra

    1718 Points


26,282 questions
33,842 answers
80,382 comments
31,192 users