ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a[] = {1, 2, 3, 4, 5, 6};
int *l = a, *r = a + 5;
while (l < r) {
int t = *l;
*l++ = *r;
*r-- = t;
}
for (int i = 0; i < 6; i++) printf("%d", a[i]);
}- A. 654321
- B. 615243
- C. 123456
- D. 654123
Correct answer: A. 654321
Each iteration swaps the two ends and moves both pointers inward, so the array is reversed in place. Forgetting to move the pointers after the swap would give a different pattern.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {4, 1, 7, 3, 9}, p[6] = {0}; for (int i = 0; i < 5; i++) p[i + 1] = p[i]…
- A qsort comparator must order the uint16t values by high byte descending and, for equal high bytes, by low byte ascending. What is…
- What is printed? c #include <stdio.h> unsigned sumd(unsigned n) { return n == 0 ? 0 : n % 10 + sumd(n / 10); } int main(void) {…
- How many subsets of {1, 2, 3, 4, 5, 6} (the empty set included) have a sum divisible by 3? Compute with this program. c #include <stdio.h>…
- What is printed by the first two calls? c #include <stdio.h> unsigned next(void) { static unsigned s = 1; s = s 1103515245u + 12345u…
- What is printed? c #include <stdio.h> int main(void) { int total = 0; for (unsigned x = 1; x <= 100; x++) { unsigned y = x; while (y) {…