So, my professor asked me to implement recursion in different ways to compute $ a^n$ (a and n being integers) and rank them according to their space efficiency. Now, here is one of the methods I came up with:

` int Power (int a, int n) { if ( n == 0 ) return 1; if ( n % 2 == 0) return Power(Power(a, n/2), 2); else return Power(Power(a, n/2), 2)*a; } `

The code compiles well, but leads to a segmentation fault. On debugging, I came to the conclusion that recursive call within the argument list is not acceptable. That is, something like

` return Power(Power(a, n/2), 2) `

or

` int m = Power(a, n/2); return Power(m, 2); `

is not allowed but

` int m = Power(a, n/2); return m*m; `

is allowed. Why is this the case? Is this true only in C++, or is it a general phenomenon?