ProgrammingModerateGATE CS · Campus placements
int m[3][4]; int *f = &m[0][0]; Which expression refers to the same element as m[2][1]?
- A. f[2*3+1]
- B. f[1*4+2]
- C. f[9]
- 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
- int m[3][4]; What is sizeof(m) / sizeof(m[0][0])?
- int a[] = {1, 2}; int b[] = {3, 4}; int x = a, y = b; void swap(int p, int q) { int t = p; p = q; q = t; } After swap(&x, &y) runs, what…
- A recursive function is written as int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }. What is gcd(1071, 462)?
- Starting at n = 27, the loop while (n != 1) { n = (n % 2) ? 3 n + 1 : n / 2; steps++; } runs with int n. What is steps at the end?
- Using square-and-multiply on int values with a reduction modulo 1000 after each multiplication, what is 3^13 mod 1000?
- How many 6-bit masks have exactly two 1 bits and have bit 0 cleared?