Using scanf in a while loop

前端 未结 5 922
庸人自扰
庸人自扰 2020-12-11 01:49

Probably an extremely simple answer to this extremely simple question:

I\'m reading \"C Primer Plus\" by Pratta and he keeps using the example

while          


        
5条回答
  •  不知归路
    2020-12-11 02:31

    In C, 0 is evaluated to false and everything else to true. Thus, if scanf returned EOF, which is a negative value, the loop would evaluate to true, which is not what you'd want.

提交回复
热议问题