As everyone mentioned here, this is basically recursion.
Just to get a feel of how this program works, I have made the recursion tree with initial fibIndex
as 5
.
5 5 calls 4 and 3.
/ \
4 3 4 calls 3 and 2. 3 calls 2 and 1.
/ \ / \
3 2 2 1 1 is base case, returns 1.
/ \ / \ / \
2 1 1 0 1 0 2 is not base case. So calls 1 and 0.
/ \
1 0