The first issue is why does exp <= 0
return 1.
By definition, anything with a 0 as an exponent is 1. So,
1^0 => 1
2^0 => 1
...
As for the second part, this is recursion at work. If I call recurPower(2, 6)
I will get a series of calls that looks like
recurPower(2, 6) =>
2 * recurPower(2, 5) =>
2 * 2 * recurPower(2, 4) =>
...
2 * 2 * 2 * 2 * 2 * 2 * 1
which is the answer.
So, in English, 2 ^ 6 is the exact same as 2 * 2 ^ 5. We use this rule to break it down into simpler and simpler exponents.