I have written a program to reverse a string using recursion. But the output I get is an empty string always.
I want to know what is wrong with my logic?
#include<stdio.h>
void reverse(char a[], int start, int end)
{
char t;
if(start>=end)
return;
else
{
t = a[start]; a[start] = a[end]; a[end] = t;
reverse(a,++start,--end);
}
}
int main(void)
{
char a[] = "hello";
int n = sizeof(a)/sizeof(a[0]);
printf("Given string is : %s ",a);
reverse(a,0,n-1);
printf("Reversed string is : %s ",a);
return 0;
}
The output:

Printing the individual characters I get,
start+1andend-1instead of++and--. The variable mutations are unnecessary and only serve to confuse things.