ProgrammingHardGATE CS · Product company OA
What is printed?
What is printed?
int sum(int (*r)[3], int n) {
int s = 0;
for (int i = 0; i < n; i++) s += r[i][i % 3];
return s;
}
int main(void) {
int m[4][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};
printf("%d", sum(m + 1, 3));
}- A. 27
- B. 22
- C. 24
- D. 15
Correct answer: C. 24
m + 1 points at row 1, so inside sum r[0] is m[1]. The diagonal it adds is r[0][0] = 4, r[1][1] = 8, r[2][2] = 12, total 24. '15' is the diagonal 1 + 5 + 9 of the whole matrix.
More C Programming questions
- What is printed? c int even(int n); int odd(int n) { return n == 0 ? 0 : even(n - 1); } int even(int n) { return n == 0 ? 1 : odd(n - 1)…
- What is printed? c char w[] = {"pear", "fig", "apple", "kiwi"}; for (int i = 0; i < 3; i++) for (int j = 0; j < 3 - i; j++) if…
- What is printed? c int score = 73; char g = score >= 90 ? 'A' : score >= 75 ? 'B' : score >= 60 ? 'C' : 'D'; printf("%c%d", g, g - 'A');
- Which of these statements about C (not C++) are true? (i) A const int variable at file scope is a constant expression, so it can size a…
- Which of these is NOT allowed for a variable declared with the register storage class in C?
- What does p(5) print? c void p(int n) { if (n <= 0) return; p(n - 2); printf("%d", n); p(n - 3); }