Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why does C code enter an infinite loop when inputting floating-point and plastic?
Why does C code enter an infinite loop when inputting floating-point and plastic?
scanf("%d ",a);

Here, scanf will detect whether the user input is an integer. If it is an integer, it will read the content assigned to from the buffer. If it is not, it will not be assigned to A, so what is the user's input?

Will stay in the buffer, resulting in the next scanf reading, because there is something in the buffer, it will be read directly from the buffer, and the result still does not match, or it will stay in the buffer.

Buffer, that's it. It will last forever. So it caused an infinite loop.