If the next character to be read cannot be converted to the current format, as indicated by the format specifier, scanf stops scanning and saves the current field, and it moves to the next input field (if any).
And this particular character is considered unread and is used as the first character of the next input field or any subsequent read operation.
In the above example, it scans 3 and then cannot resolve . format specifier "%d" . Therefore, it saves 3 in the variable a , leaving .9 unread. The control, when it moves to the next scanf statement, validates . but again, since he cannot resolve . format specifier "%d" , it skips the input scan for this field.
Now that the variable b not been assigned, it contains some garbage value. And any arithmetic operation with garbage values results in garbage values.
source share