ProgrammingModerateGATE CS · Campus placements

int m[3][4]; int *f = &m[0][0]; Which expression refers to the same element as m[2][1]?

  1. A. f[2*3+1]
  2. B. f[1*4+2]
  3. C. f[9]
  4. D. f[2+4*1]

Correct answer: C. f[9]

Rows of m[3][4] are stored one after another, so m[i][j] is f[i*4 + j]. For i = 2 and j = 1 that is f[9]. Using 3 as the row length (f[2*3+1]) is the common slip.

More C Programming questions

Exams that ask this topic