ProgrammingHardGATE CS · Product company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int a[3][4] = {0};
int (*p)[4] = a;
int *q = &a[0][0];
printf("%td %td %td", (p + 2) - p, (char *)(p + 1) - (char *)p, &a[2][1] - q);- A. 2 16 9
- B. 8 16 9
- C. 2 4 9
- D. 2 16 6
Correct answer: A. 2 16 9
p points to a whole row (4 ints = 16 bytes), so (p + 2) − p is 2 rows and p + 1 is 16 bytes past p. &a[2][1] is element 2·4 + 1 = 9 counted from &a[0][0]. '4' treats p as an int pointer; '6' uses 3 columns instead of 4.
More C Programming questions
- What is printed? c int calls = 0; int f(int n) { calls++; return n < 2 ? n : f(n / 2) + f(n - 1); } int main(void) { int r = f(6)…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xB8; / 1011 1000 / printf("%u %u %u", x & (x - 1), x | (x - 1), x & -x);
- What is printed? c int f(void) { static int n = 5; return n--; } int main(void) { int s = 0; while (f() > 2) s++; printf("%d %d", s, f()); }
- What is printed? c #define MUL(a, b) a b #define ADD(a, b) a + b printf("%d", MUL(ADD(1, 2), ADD(3, 4)));
- Assume little-endian, 8-bit char and 32-bit unsigned int. What is printed? c union { unsigned int u; unsigned char b[4]; } x; x.u =…
- What is printed? c int a = 6, b = 2; int r = a & 3 << b | 1; printf("%d", r);