How to check if two integers are equal without using comparison and arithmetic operators in C

1 Answer

0 votes
#include <stdio.h>

int equal(int x, int y) {
    return !(x ^ y);
}
 
int main(void)
{
    int a = 12, b = 12;
 
    if (equal(a, b)) {
        printf("yes");
    }
    else {
        printf("no");
    }
 
    return 0;
}




/*
run:

yes

*/

 



answered Nov 1, 2021 by avibootz
...