1#include <stdio.h>2 /*3 title: The elements of an array are printed in recursive positive/reverse order, and the process of recursive invocation is understood4 positive sequence Printing array: First: array elements are contiguous. Knowing the address of the first element, you can deduce the address of the second element. etc.5 Second: The end condition of the array: i = sizeof (arr)/4-1; At this time the value is arr[sizeof (arr)/4-1];6 Third: Subscript of the value of the next element = Subscript +1 of the value of the previous element (general formula)7 */8 voidARR1 (int*p,intNint*p1);9 voidARR2 (int*p,intn);Ten intMainvoid) One { A intarr[8] = {1,2,3,4,5,6,7,8}; - intK =0; -ARR1 (arr,0, &k);//Positive Order theprintf"k =%d\n", k);//The return process of the call -ARR2 (arr,7);//Reverse - - + return 0; - } + //recursive positive sequence printing of array elements A voidARR1 (int*p,intNint*p1) at { - if(n = =7)//End Condition -printf"%d\n", * (p+n)); - Else - { -printf"%d\t", * (P+n));//Print Current element inARR1 (p,n+1, p1);//continue calling yourself, sending the first address and the offset. Note: Return to ARR1 (P,N+1,P1); Semicolon executes (*P1) + +; Then execute} at the end of execution of the function} -(*P1) + +;//that is, return the contents after executing the CALL statement until the function ends. to } + } - //Print array elements recursively in reverse order the voidARR2 (int*p,intN) * { $ if(n = =0)//End ConditionPanax Notoginsengprintf"%d\n", * (p+n)); - Else the { +printf"%d\t", * (P+n));//Print Current element AARR2 (p,n-1);//continue calling yourself, sending the first address and the offset. the } +}
Print an array in recursive positive/reverse order, and call back the procedure to understand