segmentation fault on a recursive function
问题 I simply want to test something. I am wondering what I did wrong? #include <iostream> using namespace std; unsigned long pwr(unsigned long n, unsigned long m) { if(m == 0) n = 1; if(m == 1) n = n; n = pwr(n, m/2) * pwr(n, m/2); return n; } int main () { unsigned long n(2), m(16); cout << pwr(n, m); return 0; } output is Segmentation fault 回答1: There is no exit from recursion. You may wanted if(m == 0) n = 1; else if(m == 1) n = n; else n = pwr(n, m/2) * pwr(n, m/2); return n; 回答2: Infinite