Print an array in recursive positive/reverse order, and call back the procedure to understand

Source: Internet
Author: User
Tags call back

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.