My friend have just started learning programming. He showed me his code and asked why it return some weird number. After taking a look at it, I saw that he was using sca
The posted code does not work because it causes undefined behavior. The .
character is not a valid directive or modifier for scanf()
format strings. According to §7.21.6.2 13 of the C Standard, "If a conversion specification is invalid, the behavior is undefined".
Frighteningly, one consequence of undefined behavior may be that code appears to work, at least sometimes. But then code may fail spectacularly under different circumstances, or on different platforms. This highlights the importance of always reading the documentation for any functions being used, with special attention paid to what the Standard has to say.