- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - <iso646_h.h>
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.
There are eleven macros which are derieved from the header iso646.h −
| Macro | Token |
|---|---|
| and | && |
| and_eq | &= |
| bitand | & |
| bitor | | |
| compl | |
| not | ! |
| not_eq | != |
| or | || |
| or_eq | |= |
| xor | ^ |
| xor_eq | ^= |
Example
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;
}
Output
The above code produces the following result −
Sum of 5 and 3 = 1
Example
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;
}
Output
On execution of above code, we get the following result −
After swapping: x = 3, y = 5
Example
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;
}
Output
After executing the code, we get the following result −
Logical AND of 1 and 0 = 0
Advertisements