【发布时间】:2017-08-18 07:26:39
【问题描述】:
我在 C 中发现了这个反转字符串的代码。此代码使用递归,我无法理解 reverse() 函数。任何人都可以帮忙。
#include <stdio.h>
void reverse() //recursive function to reverse string.
{
char c;
scanf("%c",&c);
if(c!='\n')
{
reverse();
printf("%c",c);
}
}
void main()
{
printf("\nenter a string: ");
reverse();
getch();
}
【问题讨论】:
-
通过打印字符after调用reverse,它以相反的顺序打印。尝试将
printf语句 before 反向放置。
标签: c string recursion reverse