Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
Practice Tech Mahindra Essay Topics

Program Discussion :: Strings

Home > Programs > Strings

42 / 59

Write recursive function for reversing a string.

Answer:

#include


char* reverseString(char* str);

int main()
{
    int i, j, k;
    char str[100];
    char *rev;
    printf("Enter the string: ");
    scanf("%s",str);
    rev=reverseString(str);
    printf("The reversed string is: %s ",rev);
    return 0;
}
char* reverseString(char *str)
{
    static int i = 0;
    static char rev[100];
    if(*str)
    {
        reverseString(str+1);
        rev[i++]=*str;
    }
    return rev;
}

Asked In :: Global Edge

Post Your Answer Here:

Language:

Post Your Reply Here: