【发布时间】:2016-10-15 14:18:14
【问题描述】:
我试图用 C 语言理解这种程序,但我不能。确切地说,我不知道 *s 是如何改变的,以及为什么编译器显示 210012。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void WhatIamDoing(char *s) {
char ch;
if (*s) {
ch = *s;
s++;
WhatIamDoing(s);
putchar(ch);
}
}
int main() {
char s[20] = "012" ;
WhatIamDoing(s) ;
printf( "%s", s ) ;
}
【问题讨论】:
-
对不起。这不是“解释代码”或辅导网站。见How to Ask。
-
@Olaf 谁说的?
-
你听说过递归吗?特别是关于头递归?
-
"compiler shows 210012" --> 你的输出不包括
l和k吗?建议准确发布输出。 -
@chux 我这样做是为了调试。
标签: c function pointers recursion