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;
}
Discussion:
25 comments Page 3 of 3.
Madhureddy said:
1 decade ago
What vennila said is correct but you should perform & operation rather | operation.
Roh said:
1 decade ago
Answer is correct but no clear explanation.
So, can someone give detailed explanation?
So, can someone give detailed explanation?
Vennila.p said:
1 decade ago
@Imran
The solution is :
Binary format of 4 = 0100 and 8 = 1000
Therefore 4|8 is = 0100|1000 = 1100 = 12
Similary 8|4 is also 1100
now i|j & j|i=1100 & 1100 =1100=12
Then i|j && j|i =12&&12 condition is true .. so it return 1.
Then i^j = 0100^1000 = 1100 = 12.
The solution is :
Binary format of 4 = 0100 and 8 = 1000
Therefore 4|8 is = 0100|1000 = 1100 = 12
Similary 8|4 is also 1100
now i|j & j|i=1100 & 1100 =1100=12
Then i|j && j|i =12&&12 condition is true .. so it return 1.
Then i^j = 0100^1000 = 1100 = 12.
Imran said:
1 decade ago
I am not understanding
Neetu said:
1 decade ago
4= 0100
8= 1000 it will give 4|8 = 1100 & 1100 = 1100 equals to 12
4^8 = 1100 = 12
8= 1000 it will give 4|8 = 1100 & 1100 = 1100 equals to 12
4^8 = 1100 = 12
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers