See an example before a function is implemented
void Fun (int i) {if (i > 0) Fun (I/2);p rintf ("%d", I);} int main (void) {fun (ten); return 0;}
What is the output of the result?
This is an example of the "C language in depth" in this example printf ("%d", I); The statement is a part of the fun function that must execute once the fun function is printed once. The function expansion process is as follows:
void Fun (int i) {//fun (I/2), if (i > 0) {if (I/2 > 0) {if (I/4 > 0) {...} printf ("%d", I/4);} printf ("%d", I/2);} printf ("%d", I);}
Is it a lot clearer?
The same idea to complete the reverse_string (char *string) function code is as follows:
/* Write a function reverse_string (char * string) (Recursive implementation) */#include <stdio.h> #include <math.h>void reverse_string ( Char *string) {if (* (++string) = ' string-1 ') reverse_string (string);p rintf ("%c", * ());} int main () {char *a = "ABCDE"; reverse_string (a);p rintf ("\ n"); return 0;}
Reverse_string (char *string) recursively implements string rollover