为什么下面的代码有正确的输出? int GGT没有返回语句,但代码仍然工作?没有设置全局变量。函数返回值无返回语句
#include <stdio.h>
#include <stdlib.h>
int GGT(int, int);
void main() {
int x1, x2;
printf("Bitte geben Sie zwei Zahlen ein: \n");
scanf("%d", &x1);
scanf("%d", &x2);
printf("GGT ist: %d\n", GGT(x1, x2));
system("Pause");
}
int GGT(int x1, int x2) {
while(x1 != x2) {
if(x1 > x2) {
/*return*/ x1 = x1 - x2;
}
else {
/*return*/ x2 = x2 - x1;
}
}
}
打开警戒线直到你的编译器,你应该得到一个消息... – 2011-01-10 08:30:32
我收到一条警告消息,但我interessted为什么它的工作,该编译器设置了一个返回值,如果那里没人? – 2011-01-10 08:32:53
[C函数定义为int,但在主体中没有return语句的可能重复仍然编译](http://stackoverflow.com/questions/4260048/c-function-defined-as-int-but-having-no- return-statement-in-the-body-still-compi) – 2015-05-13 07:04:24