爲什麼下面的代碼有正確的輸出? 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