C 库 - <iso646_h.h>



C 库头文件 <iso646_h.htm> 允许使用替代运算符,例如 andxornot 等,它们返回特定值。例如,在布尔表达式中使用 "and" 代替 && 可以使代码更易读。

有十一个宏派生自 iso646.h 头文件:

标记
and &&
and_eq &=
bitand &
bitor |
compl ˜
not !
not_eq !=
or ||
or_eq |=
xor ^
xor_eq ^=

示例

以下是 C 库头文件 <iso646_h.htm> 的演示,使用替代运算符 ('and') 对两个数字进行运算。

Open Compiler
#include <stdio.h> #include <iso646.h> int main() { int a = 5; int b = 3; // Using the alternative 'and' operator int sum = a and b; printf("Sum of %d and %d = %d\n", a, b, sum); return 0; }

输出

以上代码产生以下结果:

Sum of 5 and 3 = 1

示例

我们创建了一个使用替代运算符 (xor) 交换两个数字的程序。

Open Compiler
#include <stdio.h> #include <iso646.h> int main() { int x = 5; int y = 3; // Using the alternative 'xor' operator x = x xor y; y = x xor y; x = x xor y; printf("After swapping: x = %d, y = %d\n", x, y); return 0; }

输出

执行上述代码后,我们得到以下结果:

After swapping: x = 3, y = 5

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

示例

下面的程序使用替代运算符计算两个值的逻辑“and”。

Open Compiler
#include <stdio.h> #include <iso646.h> int main() { int bool1 = 1; int bool2 = 0; int result = bool1 and bool2; printf("Logical AND of %d and %d = %d\n", bool1, bool2, result); return 0; }

输出

执行代码后,我们得到以下结果:

Logical AND of 1 and 0 = 0
广告