ProgrammingVery hardGATE CS · Campus placements
int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; int *p = &a[0][0]; printf("%d", p[4]); What is printed?
- A. 4
- B. 5
- C. 6
- D. 2
Correct answer: B. 5
Rows are stored contiguously, so p[4] is element a[1][1], which is 5. Indexing a 2D array through a flat pointer is valid when the index stays in range.
More C Programming questions
- int a[] = {10, 20, 30}; printf("%d", a + 2); What is printed?
- int a[] = {10, 20, 30}; printf("%d", 2[a] - a[1]); What is printed?
- How many subsets of {1, 2, 3, 4, 5, 6} have an element sum equal to 7?
- In a 3 x 3 grid, a walker can move only right or down from the top-left corner to the bottom-right corner. How many distinct paths exist?
- T(0) = 0 and T(n) = T(n-1) + n for n >= 1. What is T(10)?
- What is gcd(48, 180) by Euclid's recursion?