ProgrammingHard
On a machine with 4-byte int, what does sizeof(*r) give when int (*r)[3] is a pointer to a row of three ints?
- A. 4
- B. 8
- C. 12
- D. 3
Correct answer: C. 12
r points to an array of three ints, so *r is the whole row of type int[3] and sizeof *r = 3 x 4 = 12. 4 is sizeof **r (one int), and 3 counts the elements rather than the bytes.
More C Programming questions
- Three rows are each malloc'd separately, and their pointers are stored in an array rowp[3]. Which cleanup order is correct?
- A matrix of n x n values is read and the program needs the sum of all cells above the main diagonal. What is the cost, and is it correct…
- For a 2D prefix sum with P[i][j] = sum of the first i rows and j columns, what is the cost of building it for an n x n grid?
- int grid[4][4] is filled by grid[i][j] = i j. What is grid[3][2]?
- For the grid [[1, 2, 3], [4, 5, 6]], what is the sum of the column 2 values (the third column, 0-based index 2)?
- In row-major order, the cell a[i][j] of a matrix with C columns sits at which flat index?