ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[3][4];
int n = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 4; j++)
a[i][j] = n++;
int *p = &a[0][0];
printf("%d %d", *(p + 6), *(*(a + 2) + 1));
}- A. 6 9
- B. 8 9
- C. 6 8
- D. 5 9
Correct answer: A. 6 9
Element 6 in row-major order is a[1][2] = 6, because each row has four ints. Pointer arithmetic over a flat view uses the row length 4, and a[2][1] = 9.
More C Programming questions
- Assume int is 4 bytes. What is printed? c #include <stdio.h> int main(void) { int a[10]; int p = &a[7], q = &a[2]; printf("%ld %ld"…
- Assume a pointer is 8 bytes and int is 4 bytes. What is printed? c #include <stdio.h> void f(int v[]) { printf("%zu ", sizeof v); } int…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "hi0there"; printf("%zu %zu", sizeof s, strlen(s)); }
- What is printed? c #include <stdio.h> int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m…
- What is printed? c #include <stdio.h> unsigned long long g(unsigned n, unsigned long long acc) { return n == 0 ? acc : g(n - 1, acc 3 +…
- What is printed? c #include <stdio.h> long long memo[50]; int calls = 0; long long f(int n) { calls++; if (n < 2) return 1; if (memo[n])…