Can anyone help me understand how this string reversing works ?
#include <stdio.h>
void reverse();
int main()
{
printf("Enter a sentence: ");
reverse();
return 0;
}
void reverse()
{
char c;
scanf("%c", &c);
if( c != '\n')
{
reverse();
printf("%c",c);
}
}
In this code the function reverse is capable of getting the input sentence one character at a time, right ? And if it is not '\n' it calls the reverse function again. so the next time when the second character is taken, the second character will be in variable c, right ?
If so, how is this code able to reverse any string that is given ? And what will be the final value in c ?