ProgrammingHardInfosys · Wipro
What is printed?
What is printed?
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "stressed";
char *a = s, *b = s + 7;
while (a < b) {
char t = *a;
*a++ = *b;
*b-- = t;
}
printf("%s", s);
}- A. desserts
- B. stressed
- C. dessrets
- D. dessert
Correct answer: A. desserts
The two pointers swap characters from both ends of the 8-character string, so the result is desserts. The pointer on the left must move after each swap as well, or characters are overwritten.
More C Programming questions
- What is printed? c #include <stdio.h> unsigned parse(const char s) { unsigned n = 0; while (s) n = n 10 + (unsigned)(s++ - '0'); return n…
- What is printed? c #include <stdio.h> int main(void) { long long x = (1LL << 40) + 5; printf("%d", (int)(x & 0xFFFFFFFFLL)); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof('a')); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", ~5 & 0xF); }
- What is printed? c #include <stdio.h> int main(void) { unsigned char c = 254; int n = 0; while (++c) n++; printf("%d", n); }
- How many iterations does this binary search make to find 13 in the sorted array 0 to 15? Compute with the program. c #include <stdio.h>…