Dlaczego następujący kod ma poprawne wyjście? int GGT nie ma zwrotu, ale kod i tak działa? Nie ma ustawionych zmiennych globalnych.Funkcja zwraca wartość bez instrukcji return
#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;
}
}
}
Przekręć poziom ostrzegawczy w górę na kompilator, a powinieneś otrzymać komunikat ... –
Otrzymuję komunikat ostrzegawczy, ale interesuje mnie, dlaczego działa, czy kompilator ustawia wartość zwracaną, jeśli nie ma nikogo? –
możliwy duplikat funkcji [C zdefiniowanej jako int ale bez instrukcji return w treści nadal kompiluje] (http://stackoverflow.com/questions/4260048/c-function-defined-as-it-but-having-no- return-statement-in-the-body-still-compi) –