I was reading a thread about XOR, and having to do this for my current program had a question on it.
I know && and || are part of C,
so isnt there a way to have an XOR without doing several basic operations?(Like a command I havent yet seen)
I was reading a thread about XOR, and having to do this for my current program had a question on it.
I know && and || are part of C,
so isnt there a way to have an XOR without doing several basic operations?(Like a command I havent yet seen)
>>so isnt there a way to have an XOR without doing several basic operations?(Like a command I havent yet seen)
Sure, the ^ operator performs an XOR and ^= does an XOR then assignment :-)
Code:/* How to set an int to 0 without saying var = 0; */ #include <stdio.h> #include <stdlib.h> int main(void) { int a = rand(); printf("%d\n", a); a ^= a; printf("%d\n", a); return 0; }
*Cela*
the != operator.
All that xor does is return true if either operand is true, but not both. That's exactly what != does (considering you are dealing with just a single value representing true and a single value representing false ).
If you want the bitwise version of xor it actually has its own operator which is ^