It activates Triangle()
with a parameter of 1.
Finally we are at the base case.
When Triangle()
is activated with a parameter of 1,
the if
statement causes the
value 1
to be immediately returned.
The chain of activations is called an activation chain. The picture on this page shows the activation chain when it has reached the base case. The base case immediately returns a one.
int Triangle( int N ) { if ( N == 1 ) return 1; else return N + Triangle( N-1 ); }
Now look again at the activation where N = 2
.
The if-statement selects the false-branch and Triangle(1)
returns the value one:
What value does this activation return to its caller?