Yes, using not whitespace characters in a
scanf format string is legal. Those characters are expected to be read and skipped over. If those characters are not given in the input,
scanf stops reading at that point.
For example, if your input was
3 would be stored in
- would match the pattern, and the
4 would be stored in
b so the output would be 7.
If on the other hand you inputted
4x5, the 4 would be stored in
a but the
x would halt reading of further input because it does not match
b would have an undefined value and the result of adding a value to it would also be undefined.