As number had not been initialized and scanf()
failed the printf()
provokes undefined behaviour reading the uninitialised variable number
. Anything could happen.
So there are two lessons to learn here:
- Initialise variables when they are defined. (If you do not know to what to initialise them you most probably do not need them, at least not where you are trying to define them)
- Perform error checking on calls which would return garbage if failed.