C Programming - Bitwise Operators - Discussion

Discussion Forum : Bitwise Operators - Find Output of Program (Q.No. 12)
12.
What will be the output of the program ?
#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;
}
4, 8, 0
1, 2, 1
12, 1, 12
0, 0, 0
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 2 of 3.

Yasaswini said:   8 years ago
@Sana.

X and y values are defined as constant.
So values don't change.
The answer is 50 60 110.
If it is wrong pls tell me how it comes?

Tarun Ghosh said:   10 years ago
^ this is binary XOR operator. Perform Bit-wise XOR operation Means odd no. of 1 is 1 otherwise 0. Then you will get your answer.

Wikiok said:   1 decade ago
& (bit AND) has in higher precedence than | (bit OR).So
4|8&8|4 == (4| (8&8) | 4) == ((4|8)|4) == (12|4) == 12

Rahul said:   1 decade ago
Bitwise & has more precedence comp then bitwise or why you first solve bitwise or please tell me.

Neetu said:   2 decades ago
4= 0100

8= 1000 it will give 4|8 = 1100 & 1100 = 1100 equals to 12

4^8 = 1100 = 12

Roh said:   1 decade ago
Answer is correct but no clear explanation.

So, can someone give detailed explanation?

Madhureddy said:   1 decade ago
What vennila said is correct but you should perform & operation rather | operation.

Sudha said:   1 decade ago
@Neetu.

The output is:

51 59 110

The correct or not.

Please anyone tell me.

Sana said:   1 decade ago
Can any one please tell me if i=4 and j=8 then how i&&j and i||j done?

Aalapini said:   10 years ago
Can some one explain i^j part? The function of ^ operator specifically.
(1)


Post your comments here:

Your comments will be displayed after verification.