Interview Questions and Answers :: Cisco
Home > Experience Archives > Cisco > Interview Question Set 2 > Discussion
1. Reverse a string in C using as little additional memory as possible.
Answer:
// C program using recursion to reverse a string.
# include
void reverseString(char *str)
{
if (*str)
{
reverseString(str+1);
printf("%c", *str);
}
}
int main()
{
char a[] = "India is a great country";
reverseString(a);
return 0;
}
Ankit Sharma
26 Jul, 2016 12:39 PM
// C program using recursion to reverse a string.
# include
void reverseString(char *str)
{
if (*str)
{
reverseString(str+1);
printf("%c", *str);
}
}
int main()
{
char a[] = "India is a great country";
reverseString(a);
return 0;
}
# include
void reverseString(char *str)
{
if (*str)
{
reverseString(str+1);
printf("%c", *str);
}
}
int main()
{
char a[] = "India is a great country";
reverseString(a);
return 0;
}
Report Error
Report Error
Please Login First Click Here