Why does the following code execute - when a decimal number is entered - at first, but on the second iteration scanf directly returns 0, and the loop breaks?
#include <stdio.h>
int main(){
int num = 1;
while(num != 0){
printf("input integer: ");
if(scanf("%d", &num) == 0)
break;
printf("out: %d\n", num);
}
return 0;
}
If I enter, for example, 5.55, it prints 5 (scanf returns 1 and printf executes), however on the next iteration it [scanf] returns 0 and the loop breaks. Why does scanf return 1 in the first place?