ProgrammingHard
With int a[3][4] (4-byte int, row-major), what is the value of (int *)&a[1][0] - (int *)&a[0][0]?
- A. 3
- B. 4
- C. 12
- D. 16
Correct answer: B. 4
Subtracting two int pointers gives the number of ints between them, not bytes. Row 1 starts four ints after row 0.
More C Programming questions
- With int a[3][4] (4-byte int) and int (p)[4] = a, what is (char )(p + 2) - (char )p?
- Matrix m = {{1,2,3},{4,5,6},{7,8,9}} is rotated 90 degrees clockwise. What is the first row after rotation?
- Matrix m = {{1,2,3},{4,5,6},{7,8,9}} is transposed in place. What is the first row afterwards?
- Spiral traversal (clockwise, starting top-left) of the 3 x 4 matrix with rows {1,2,3,4}, {5,6,7,8}, {9,10,11,12} visits the elements in…
- int g[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; With a 2D prefix-sum table P, the sum of the rectangle with rows 1 to 2 and columns 1 to 2…
- Count the 4-connected islands of 1s in this grid, where rows are "11000", "11010", "00100", "00011". How many islands are there?