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));
  1. A. 13 10
  2. B. 9 10
  3. C. 13 9
  4. 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

Exams that ask this topic