C Library –


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 = %dn", 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 = %dn", 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 = %dn", bool1, bool2, result);
    return 0;
}


Output

After executing the code, we get the following result −


Logical AND of 1 and 0 = 0

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *