我知道签名是
int scanf(const char *format, ...)
Run Code Online (Sandbox Code Playgroud)
这个int值与什么有关?
NPE*_*NPE 40
从man
页面:
NAME
scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf
...
RETURN VALUE
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.
The value EOF is returned if the end of input is reached before either
the first successful conversion or a matching failure occurs. EOF is
also returned if a read error occurs, in which case the error indicator
for the stream (see ferror(3)) is set, and errno is set indicate the
error.
Run Code Online (Sandbox Code Playgroud)
在你的情况下,scanf()
可以返回0
,1
或EOF
.
PS正如其他人所指出的那样,你在前面错过了一个&符号man
:
NAME
scanf, fscanf, sscanf, vscanf, vsscanf, vfscanf
...
RETURN VALUE
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.
The value EOF is returned if the end of input is reached before either
the first successful conversion or a matching failure occurs. EOF is
also returned if a read error occurs, in which case the error indicator
for the stream (see ferror(3)) is set, and errno is set indicate the
error.
Run Code Online (Sandbox Code Playgroud)
没有&符号,代码的行为是不确定的.