ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int m[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
m[i][j] = i * 3 + j + 1;
int *row = &m[0][0];
int s = 0;
for (int i = 0; i < 3; i++)
s += m[i][2 - i];
printf("%d", s);
}- A. 12
- B. 15
- C. 9
- D. 18
Correct answer: B. 15
The anti-diagonal entries are m[0][2] = 3, m[1][1] = 5 and m[2][0] = 7, summing to 15. The pointer row is unused and does not affect the result.
More C Programming questions
- How many times is disk 3 moved in this recursive Towers of Hanoi with 5 disks? Compute the program output. c #include <stdio.h> int cnt =…
- How many integers n with 1 <= n <= 64 satisfy both (n & (n - 1)) == 0 and (n & 0x55555555u) != 0? Compute with this program. c #include…
- What is printed? c #include <stdio.h> int main(void) { int a[5]; int p = a + 4, q = a + 1; printf("%ld", (long)(p - q) (long)sizeof p); }
- What is printed? Assume int is 32 bits and integer division truncates toward zero. c #include <stdio.h> int main(void) { int v[] = {-7…
- What is the maximum value of depth printed? c #include <stdio.h> int depth = 0, maxd = 0; void r(int n) { depth++; if (depth > maxd) maxd…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; int p = a + 2; printf("%d %d", p[-1], p[2]); }