ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {1, 4, 6}, b[] = {2, 3, 8, 9};
int m[7], i = 0, j = 0, k = 0;
while (i < 3 && j < 4) m[k++] = a[i] <= b[j] ? a[i++] : b[j++];
while (i < 3) m[k++] = a[i++];
while (j < 4) m[k++] = b[j++];
printf("%d", m[4]);
}- A. 4
- B. 8
- C. 3
- D. 6
Correct answer: D. 6
The merged array is 1, 2, 3, 4, 6, 8, 9, so index 4 holds 6. The second merge loop copies the remaining elements of a when b is exhausted.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {3, 9, 2, 9, 1}, n = 5; int mx = a; for (int p = a + 1; p < a + n; p++)…
- What is printed? c #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…
- How many pairs (i, j) with i < j have an even sum? Compute with this program. c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint16t s = 0; for (int i = 1; i <= 1000; i++) s += i…
- What is printed? Assume uint64t is 64 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint64t r = 1; for (uint64t i = 1; i…
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 2; if (n - 3 < 5) puts("small"); else puts("big"); }