reverse string using recursive
Code:
#include <iostream>
#include <string>
using namespace std;
void reverse(string, int);
int main()
{
string s = "Example";
cout << s<< endl;;
reverse(s, 0);
} // end main
void reverse(string reverse, int i=0)
{
if (start == reverse.length())
return;
reverse(reverse,i+1);
cout << reverse[i];
}
I understand most of this code but only thing i don't understand is the last 2 line.
Code:
reverse(reverse,i+1);
cout << reverse[i];
how does the index goes to the end of the array when i is 0?