C Standard Library 简明教程
C library - <iso646_h.h>
C 库头文件 <iso646_h.htm> 允许替代运算符,例如 and 、 xor 、 not 等,这些运算符会返回特定值。例如,在布尔表达式中使用 "and" 而不是 && 可以使代码更具可读性。
The C library header <iso646_h.htm> allows the alternative operators such as and, xor, not, etc which return the specific value. For example, using "and" instead of && in boolean expressions can make the code more readable.
有十一种宏是从头文件 iso646.h 派生的 −
There are eleven macros which are derieved from the header iso646.h −
Example
以下是 C 库头文件 <iso646_h.htm>,以查看使用替代运算符('and')的两个数字的演示。
Following is the C library header <iso646_h.htm> to see the demonstration of two number using alternative('and') operator.
#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;
}
Example
我们创建一个程序,使用替代运算符 (xor) 交换两个数字。
We create a program for swapping two numbers using alternative operators(xor).
#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;
}
Example
下面的程序使用替代运算符计算两个值的逻辑 " and "。
Below the program calculate the logical "and" of two values using alternative operator.
#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;
}