I was wondering whether someone could explain how this small code snippet works.
void reverse(char *s)
{
if(*s)
reverse(s+1);
else
return;
cout << *s;
}
When you call this function in main, it supposedly prints out the reverse of any string put in (ie. hello would cout as olleh) but I don't understand how. As I understand it, the if statement increases the value of s until it reaches the end of the string, printing out each value in the string as it goes. Why doesn't that just re-print the string. Clearly I am missing something. (Sorry btw, I am new to C++ and recursive functions)