252 views
0 votes
0 votes
#include<stdio.h>

int main()
{
    int i=4, j=8;
    printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
    return 0;
}

Please tell the approach.

Ans is 12 12 12

1 Answer

Best answer
1 votes
1 votes
    printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
i|j&j|i

$00000100\,\text{Bitwise OR}(00001000 \text{Bitwise AND}00001000)\text{Bitwise OR} 00000100$

$00000100\,\text{Bitwise OR}\,\,00001000 \text{Bitwise OR} \,\,00000100=00001100=(12)_{10}$


i|j&j|i

same as above-:$12$


i^j

$00000100\,\text{Bitwise XOR} \,\,00001000=00001100=(12)_{10}$

selected by