Let f be the following C++ function: void f (char *p) { char *q = p; while (*q)
ID: 3614660 • Letter: L
Question
Let f be the following C++ function:void f (char *p) { char *q = p;
while (*q) q++; while (p < q) { char ch = *p; *p++ = *--q *q = ch; } }
Assume that the argument to f is C-style (null-terminated)string.
A) What modification does f perform to the string that ispassed to it? B) Explain how f works.
void f (char *p) { char *q = p;
while (*q) q++; while (p < q) { char ch = *p; *p++ = *--q *q = ch; } }
Assume that the argument to f is C-style (null-terminated)string.
A) What modification does f perform to the string that ispassed to it? B) Explain how f works.
Explanation / Answer
please rate - thanks the characters in the string are reveres if enter the function with abcd exit with dcba starts at the beginning of the string and q steps through thestring until it gets to the end starting with the first and last characters in the string it swaps the end characters moves in one character oneach side swaps them keeps moving in and swapping 1characters untilthe 2 pointers cross each others paths (hope this makes sense)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.