ProgrammingModerateHCL · Tech Mahindra pattern
int a[3][4]; is stored in row-major order starting at address 1000, with 4-byte int. What is the address of a[2][1]?
- A. 1009
- B. 1040
- C. 1020
- D. 1036
Correct answer: D. 1036
Row-major: address = base + (row × columns + col) × size = 1000 + (2 × 4 + 1) × 4 = 1000 + 36 = 1036. 1020 comes from the column-major formula (1 × 3 + 2) × 4.
More C Programming questions
- What is printed? c unsigned char c = 250; c += 10; printf("%d", c);
- What does f(3) print? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 1); } }
- What is printed? c char a[] = "hi", b[] = "hi"; if (a == b) printf("same"); else printf("different");
- What is printed? c #define STR(x) #x #define CAT(a, b) a##b int xy = 7; printf("%s %d", STR(x+y), CAT(x, y));
- What is printed? c int x = 2; switch (x) { case 1: printf("A"); case 2: printf("B"); case 3: printf("C"); break; default: printf("D"); }
- What is printed? c int n = 5; while (n-- > 2) printf("%d", n); printf(" %d", n);