! C · 运算符
逻辑非运算符,把真(非0)变成 0,把假(0)变成 1。
怎么用
!a
小例子
#include <stdio.h>
int main(void) {
int ok = 0;
printf("%d", !ok);
return 0;
}
运行结果
输出 1
提醒:读作 not;! 的优先级比比较运算符高
官方文档:https://en.cppreference.com/w/c/language/operator_logical
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条