char *s;
int nfrogs;
……
s=(nfrogs ==1 ) ? “” : “s”;
printf(“We found %d frog%s in the pond.\n”,nfrogs,s);
这段代码没必要的部分我省略了,就是s=(nfrogs ==1 ) ? “” : “s”这一段不知道该怎样理解。非常感谢。
固定链接: https://www.vcgood.com/archives/2607
声明: TONYAZITEN 2008年08月10日 发表于 C语言帝国
char *s;
int nfrogs;
……
s=(nfrogs ==1 ) ? “” : “s”;
printf(“We found %d frog%s in the pond.\n”,nfrogs,s);
这段代码没必要的部分我省略了,就是s=(nfrogs ==1 ) ? “” : “s”这一段不知道该怎样理解。非常感谢。
固定链接: https://www.vcgood.com/archives/2607
声明: TONYAZITEN 2008年08月10日 发表于 C语言帝国
你必须先 登录才能发表评论。
这是条件运算符‘?’和条件表达式。
s=(nfrogs ==1 ) ? “” : “s”可以表示为s=【(nfrogs ==1 ) ? “” : “s”】
如果nfrogs ==1成立,则s=”"。
如果nfrogs ==1不成立,则s=”s”。
恩 主要就是?的用法 明白了 非常感谢。