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;}