~ C · 运算符
按位取反运算符,把操作数的每个二进制位 0 变 1、1 变 0。
怎么用
~a
小例子
#include <stdio.h>
int main(void) {
printf("%d", ~0);
return 0;
}
运行结果
输出 -1
提醒:包括符号位一起取反;结果与整数宽度有关
官方文档:https://en.cppreference.com/w/c/language/operator_arithmetic
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← C全部词条