Home > Back-end >  The problems encountered in the process of learning recursive
The problems encountered in the process of learning recursive

Time:04-22

Int the sum (int n)
{
If (n==1)
return 1;
The else
Return the sum (n - 1) + n.
}
Will change for n - and - n - 1 n the result is not the same, n assignment 3, for example, use the above code to get a value of 6, n - would be an error, -- -- -- n got 4. I know n - first, after using - n first after damping but why the debug, n - shrimp every n in return for 3? Why is the return of the expression of n n results not as is called?

CodePudding user response:

Brush, I wrote more than ten years of c + + code, didn't understand,
Don't write such code in practical work,

CodePudding user response:

reference 1st floor mmcanyu response:
brush, I wrote more than ten years of c + + code, did not understand,
Don't write such code in practical work,

Well, is the principle of feeling that don't quite understand, when the DEBUG of the fog
  • Related