ProgrammingHard
Given int a[3][4] and int *q = &a[0][0], which element does q[5] refer to?
- A. a[1][2]
- B. a[0][5]
- C. a[1][1]
- D. a[2][1]
Correct answer: C. a[1][1]
q[5] is the element at flat index 5. With 4 columns that is row 1 and column 1, so a[1][1].
More C Programming questions
- int m[2][3] = {{1}, {2, 3}}; What is m[0][0] + m[1][0] + m[1][1] + m[0][2]?
- int a[3][4]; what do sizeof a / sizeof a[0] and sizeof a[0] / sizeof a[0][0] give?
- char g[3][4] = {"abc", "de", "f"}; What is the value of g[1][2] when printed with %d?
- int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; How many monotone paths (moves right or down) are there from m[0][0] to m[2][2]?
- For the grid w = {{1,3,1},{1,5,1},{4,2,1}}, what is the minimum sum of a path from top-left to bottom-right moving only right or down?
- An n x n matrix of ints is read row by row. Which code reads it correctly into int a[n][n] when n is a run-time value?