下面语句的确切含义是什么,
if (scanf("%lf", &x) != 1)
我尝试输入数字,条件为true,否则当我输入非数字字符如'a'时,条件为false。
你能告诉我更多关于 scanf()
和值 1
的信息吗?
最佳答案
我系统上的 scanf()
文档指出:
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
因此,如果找到 float ,则 scanf()
的结果为 1,否则为 0。 if
语句的主体如果返回值不是 (!=
) 则执行。
关于c - 关于 C 中 scanf() 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5799261/