In this recursive call:
reverse(no--);
You pass the value no-- . Since this uses a postfix operator, it means "decrement no , then pass the original value of no to a recursive call to reverse ". This causes infinite recursion, as you constantly make a recursive call with reverse set to the same value.
To fix it, change it to read
reverse(no - 1);
Note that there is no reason to reduce no , since in the current recursive call you will never read no again. You can simply pass the value no - 1 to the function. In fact, you might not want to use it at all -- in recursive calls, since it almost always indicates an error in the code.
Hope this helps!
source share