ProgrammingHardGATE CS · Product company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
typedef int Row[3];
Row m[2] = {{1, 2, 3}, {4, 5, 6}};
Row *p = m;
printf("%zu %d", sizeof(Row), (*++p)[1]);- A. 4 5
- B. 12 2
- C. 8 5
- D. 12 5
Correct answer: D. 12 5
Row is a typedef for int[3], so sizeof(Row) is 12 and Row * is a pointer to a whole row. ++p moves to m[1], and (*p)[1] is 5. '12 2' forgets the ++; '4' treats Row as a single int.
More C Programming questions
- What is printed? c int a = 0, b = 0, c = 0; if ((a = 2) && (b = 0) || (c = 3)) a++; printf("%d %d %d", a, b, c);
- Which line has undefined behaviour? c char a[] = "hi"; char p = "hi"; a[0] = 'H'; / (i) / p[0] = 'H'; / (ii) / char q = a; q[1] = 'I'; /…
- What is printed? c int calls = 0; int C(int n, int k) { calls++; return (k == 0 || k == n) ? 1 : C(n - 1, k - 1) + C(n - 1, k); } int…
- What is printed? c enum E { A = -2, B, C, D = A + 10, E2 }; printf("%d %d %d", B, C, E2);
- What is printed? c int steps(int n) { return n == 1 ? 0 : 1 + steps(n % 2 ? 3 n + 1 : n / 2); } int main(void) { printf("%d %d", steps(6)…
- Assume ASCII. What does f("Code21") print? c void f(const char s) { if (s) { f(s + 1); if (s % 2) putchar(s); } }