[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

326 / 60

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: