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

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

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

3 Answers

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


Top Users Jun 2017
  1. Bikram

    2512 Points

  2. Hemant Parihar

    1480 Points

  3. junaid ahmad

    1432 Points

  4. Arnab Bhadra

    1334 Points

  5. Niraj Singh 2

    1311 Points

  6. rahul sharma 5

    1060 Points

  7. Rupendra Choudhary

    1042 Points

  8. Debashish Deka

    888 Points

  9. Arjun

    856 Points

  10. srestha

    836 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 19 - 25
  1. Niraj Singh 2

    1306 Points

  2. Bikram

    768 Points

  3. junaid ahmad

    502 Points

  4. akankshadewangan24

    252 Points

  5. joshi_nitish

    250 Points


23,325 questions
29,999 answers
67,196 comments
28,337 users