#include"stdio.h" void print_rev_str(char*a) { if(*a=='\0') return; else return print_rev_str(char *(a-1)); printf("%c",*a) } int main() { print_rev_str("CJLU"); }这个程序错在哪
时间: 2024-03-03 14:48:56 浏览: 55
这个程序错在递归函数 `print_rev_str` 的写法上。具体来说,它应该是这样的:
```
void print_rev_str(char* a) {
if (*a == '\0') {
return;
} else {
print_rev_str(a + 1);
printf("%c", *a);
}
}
```
原因是,在递归函数中,应该先递归调用函数,再进行输出操作。否则,程序会永远停留在递归调用的过程中,而无法进行输出操作,最终导致栈溢出。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![image/gif](https://img-home.csdnimg.cn/images/20210720083352.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-gzip](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![exe](https://img-home.csdnimg.cn/images/20241231044909.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)