As Suraw Ghosh explains in detail, using formats that are incompatible with the actual traversed types is a potential problem. However, for this particular case, on modern PC architectures, this is not a problem, since neither int nor unsigned int have trap representations.
You can scan a negative number with scanf("%u", &number); . It will be canceled in the destination type, namely unsigned int , with the same bitwise representation as the negative number in the signed int , for two additional representations that are almost universal for current architectures.
scanf converts %u by matching an optionally signed decimal integer whose format is the same as expected for the subject sequence of the strtoul function with a value of 10 for the base argument. The corresponding argument must be a pointer to an unsigned integer.
The strtoll , strtoll , strtoul and strtoull convert the initial part of the string pointed to by nptr to long int , long long int , unsigned long int and unsigned long long int > views, respectively. Firstly, they decompose the input string into three parts: the initial, possibly empty, sequence of space characters (as determined by the isspace function), the sequence of the subject resembling an integer represented in a certain radix determined by the value of the base, and the final string of one or more unrecognized characters, including the terminating null character of the input string. Then they try to convert the sequence of objects into an integer and return the result.
If the base value is from 2 to 36 (inclusive), the expected form of the subject sequence is a sequence of letters and numbers representing an integer with a radius specified by the base, not necessarily preceding the plus or minus sign, but not including the integer suffix.
... If the sequence of objects has the expected shape and the value of the base is between 2 and 36, it is used as the basis for the conversion, assigning each letter its value, as indicated above. If the sequence of objects begins with a minus sign, the value obtained as a result of the conversion is negated (in the return type).
If number is equal to unsigned int , the behavior is determined and a negative value is analyzed and stored in number using the semantics of unsigned negation. Print this value with printf("%d", number); at best implemented, but then again, on current PC architectures, it will print a negative number that was originally parsed using scanf("%u", &number);
Conclusion: although it seems harmless, it is very careless to use int and unsigned int interchangeably and use the wrong formats in printf and scanf . In fact, mixing substituted and unsigned types in expressions, especially. in comparison, it is a very mistake, since the semantics of C for such constructions sometimes meet intuition.