ProgrammingHardProduct company OA
What is printed?
What is printed?
int r0[] = {1, 2}, r1[] = {3, 4, 5}, r2[] = {6};
int *rows[] = {r0, r1, r2};
int len[] = {2, 3, 1};
int s = 0;
for (int i = 0; i < 3; i++) s += rows[i][len[i] - 1];
printf("%d %d", s, *(*(rows + 1) + 1) + **(rows + 2));- A. 13 10
- B. 9 10
- C. 13 9
- D. 12 10
Correct answer: A. 13 10
rows is a jagged array: an array of pointers to rows of different lengths. The loop adds each row's last element, 2 + 5 + 6 = 13. *(*(rows + 1) + 1) is rows[1][1] = 4 and **(rows + 2) is rows[2][0] = 6, so the second value is 10.
More C Programming questions
- This prints every permutation of "abc". What is the FIFTH string printed? c void p(char s, int k) { if (!s[k]) { printf("%s ", s); return…
- What is printed? c int a = 1; printf("%d %d", a << 2 + 1, (a << 2) + 1 > 4 == 1);
- What is printed? c int a[] = {4, 7, 4, 9, 7, 9, 9}; int x = 0; for (int i = 0; i < 7; i++) x ^= a[i]; printf("%d", x);
- What is printed? c int a[] = {1, 2, 4, 5, 6}, x = 0; for (int i = 1; i <= 6; i++) x ^= i; for (int i = 0; i < 5; i++) x ^= a[i]…
- What is printed? c int parse(const char s) { int sign = 1, n = 0; if (s == '-') { sign = -1; s++; } while (s >= '0' && s <= '9') n = n 10…
- What is printed? c int a[] = {1, 1, 2, 3, 3, 3, 4}, k = 1; for (int i = 1; i < 7; i++) if (a[i] != a[k - 1]) a[k++] = a[i]; printf("%d…