Mega Code Archive

 
Categories / C / Code Snippets
 

Perform a logical XOR operation using the two arguments

#include <stdio.h> int xor(int x, int y); int main(void) { printf("%d", xor(1, 0)); printf("%d", xor(1, 1)); printf("%d", xor(0, 1)); printf("%d", xor(0, 0)); return 0; } int xor(int x, int y) { return (x || y) && !(x && y); }