ProgrammingVery hardGATE CS
What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage.
What is printed? Assume int is 4 bytes and the array is a 2-D array object of automatic storage.
#include <stdio.h>
int main(void) {
int a[3][4];
printf("%td %td %zu", (char *)&a[2][1] - (char *)&a[0][0],
&a[2][1] - &a[0][0], sizeof(a[1]));
return 0;
}- A. 9 36 16
- B. 36 9 16
- C. 9 9 16
- D. 36 9 4
Correct answer: B. 36 9 16
Element a[2][1] is 2 x 4 + 1 = 9 ints after a[0][0], so the int-pointer difference is 9 and the byte difference is 36. a[1] is a row of 4 ints: 16 bytes.
More C Programming questions
- What is printed? Assume IEEE-754 float (32-bit) and double (64-bit) with no extended-precision evaluation. c #include <stdio.h> int…
- What is printed? c int a[5] = {1, 2}; printf("%d %d %zu", a[1], a[2], sizeof a / sizeof a[0]);
- What is printed? c printf("%.1f %d", 7 / 2 2.0, (int)(7 / 2.0 2));
- What is printed? c printf("%d %d", 6 & 3 << 1, ~5 + 1);
- What is printed? c int n = 2, s = 0; switch (n) { case 1: s += 1; case 2: s += 2; case 3: s += 3; break; default: s += 9; } printf("%d", s);
- What is printed? c int a[] = {10, 20, 30, 40}; int p = a + 1; printf("%d %d %d", (p + 1), p[-1], (int)(&a[3] - p));