Supplement the output return value of a statement

Source: Internet
Author: User

I wrote a blog about the output of the return value of a statement. I didn't understand the execution process of the statement when I posted the blog. I want to add it here.

The original blog address is: http://blog.csdn.net/jianzhibeihang/archive/2009/12/06/4952037.aspx

 

Today, I posted a post in c and found many good replies. There are still a lot of Daniel in the version!
Source post address: http://topic.csdn.net/u/20091209/10/d7cc1cc3-3eff-43d2-8096-c66a78996b3d.html#replyachor

 

First, explain the execution process of this statement. Take p (1, 3) as an example:
The number of characters returned by the printf statement. Since/n exists, the execution of printf is always true.

Level 1: p (): printf execution true output: 1
3> 1. If execution is true, p (2, 3) or p (1, 1) is executed)
P (2, 3) or p (1, 1)
Layer 2: p (2, 3): printf execution true output: 2
3> 2 if the execution is true, p (3, 3) or p (2, 2) will be executed next)
P (3, 3) or p (2, 2)
Layer 3: p (3, 3): printf execution true output: 3
3> 3 execution is false p (3, 3) execution is false, and return to Layer 2 execution p (2, 2)
| Operator, | the expression on the left of the operation is false.
Then execute the expression on the right, so execute p (2, 2)
Returned to Layer 2 p (2, 2): printf execution true output: 2
2> 2 if false p () execution is false, then the execution of the entire p () is
False, so for the first layer p (2, 3) | p (1, 1), | expression
If the expression on the left is false, run | the expression on the right, that is, p)
Return to the first layer P (): printf to execute true output: 1
1> 1. The execution is false.
The final p function returns false and the execution ends.

 

The following is the conversion of the return sentence:

int p(int i, int N){    printf("%d/n", i);    if (N>i)    {        if (p(i+1,N)==0)            return p(i,i);        else            return  1;    }    else        return 0;}

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.