Can unverified scanf call cause an undefined behavior?
问题 Does below snippet invoke undefined behavior in case of an error? #include <stdio.h> int main() { int i; /* Indeterminate */ if (scanf("%d", &i) == 1) /* Initialize */ printf("%d\n", i); /* Success! Print read value */ else printf("%d\n", i); /* Input failed! Is printing `i` UB or not? */ return 0; } What if scanf fails, is an uninitialized variable accessed? EDIT Moreover what if I replace scanf("%d", &i) with my_initializer(&i) : int my_initializer(int *pi) { double room_temp_degc = get