#include <stdio.h>
int main(void)
{
int i, j, k;
scanf("%d%d%d", &i, &j, &k);
printf("%d %d %d", i, j, k);
return 0;
}
If we input 1,2,3
, what will happen? And why?
According to https://stackoverflow.com/a/18297691/2646069 , if scanf()
reads an unexpected string, it will return early thus not modifying any value after the last successful value.
I tried clang (LLVM 6.1.0), on -O0
, the explanation above is correct, but on -O2
, the second variable is always a random number but not the same as before scanf()
, and the third variable is always 0
.