我无法理解下面代码中表达式的计算方式。我不明白这里的代码是如何工作的
while (isdigit(s[++i] = c = getch()))
;
为什么我们需要
s[1] = '\0';
完整代码
#include <ctype.h>
int getch(void);
void ungetch(int);
/* getop: get next character or numeric operand */
int getop(char s[])
{
int i, c;
while ((s[0] = c = getch()) == ' ' || c == '\t');
s[1] = '\0';
if (!isdigit(c) && c != '.')
return c; /* not a number */
i = 0;
if (isdigit(c)) /* collect integer part */
while (isdigit(s[++i] = c = getch()));
if (c == '.') /* collect fraction part */
while (isdigit(s[++i] = c = getch()));
s[i] = '\0';
if (c != EOF)
ungetch(c);
return NUMBER;
}
感谢您的帮助!
=
是右结合的,因此 isdigit(s[++i] = c = getch())
将被分组为
是数字( s[++i] = (c = getch()) )
。 getch
将读取一个char
并将其分配给c
,然后将c
分配给s[++我]
.
我是一名优秀的程序员,十分优秀!