ProgrammingVery hardGATE CS
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int a[2][3][4];
printf("%zu %zu %td", sizeof a[1], sizeof a[1][2],
(char *)&a[1][2][3] - (char *)a);- A. 48 16 23
- B. 48 16 96
- C. 48 16 92
- D. 12 4 92
Correct answer: C. 48 16 92
a[1] is a 3 × 4 block of ints (48 bytes) and a[1][2] is a row of 4 ints (16 bytes). Element [1][2][3] is at index 1·12 + 2·4 + 3 = 23 in row-major order, and as a char-pointer difference that is 23 × 4 = 92 bytes. '23' forgets the char casts.
More C Programming questions
- Assume ASCII. What is printed? c int my(const char a, const char b) { while (a && a == b) { a++; b++; } return a - b; } int main(void) {…
- In what order are the nodes linked after the four calls? c struct N { int v; struct N nx; }; void ins(struct N h, struct N n) { while (h…
- A function in a.c is declared static int helper(void) { ... }. Which statement is true?
- What is printed? c #define MAX(a, b) a > b ? a : b int x = 3, y = 7; printf("%d", 2 MAX(x, y));
- Assume IEEE-754 single-precision float with float arithmetic done in float. Which loops terminate? c int c1 = 0, c2 = 0; for (float f = 0…
- What is printed? c struct Shape { int w, h; int (area)(struct Shape ); }; int rect(struct Shape s) { return s->w s->h; } int tri(struct…