ProgrammingHardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int m[2][3] = {{1, 2, 3}, {4, 5, 6}}, t[3][2];
for (int i = 0; i < 2; i++)
for (int j = 0; j < 3; j++)
t[j][i] = m[i][j];
printf("%d", t[2][1]);
}- A. 3
- B. 5
- C. 6
- D. 4
Correct answer: C. 6
t is the transpose of m, so t[2][1] = m[1][2], which is 6. Using m[1][1] gives 5, one of the usual index mix-ups.
More C Programming questions
- What is printed? c #include <stdio.h> int calls = 0; unsigned g(unsigned a, unsigned b) { calls++; return b == 0 ? a : g(b, a % b); } int…
- What is printed? Assume unsigned int is 32 bits and unsigned long long is 64 bits. c #include <stdio.h> unsigned long long pw(unsigned b…
- What is printed? c #include <stdio.h> void bits(unsigned n) { if (n > 1) bits(n / 2); putchar('0' + n % 2); } int main(void) { bits(11); }
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t a = 300, b = 300; uint32t p…
- What is printed? c #include <stdio.h> #include <stdlib.h> int ds(int n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } int…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char names[] = {"x", "yy", "zzz"}; char pp = names + 1…