C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 7)
7.
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:
58 comments Page 2 of 6.
Priyanka said:
1 decade ago
Simple AND and OR operation take place here.
In printf statement there is %d which asking for the decimal value of the result. And the decimal of 4 is 0100. And of 8 is 1000.
Now, by OR them we get 1100 which is the binary representation of 12 and hence the result follows.
In printf statement there is %d which asking for the decimal value of the result. And the decimal of 4 is 0100. And of 8 is 1000.
Now, by OR them we get 1100 which is the binary representation of 12 and hence the result follows.
Sk.Mosin said:
1 decade ago
Here i=4------>0100 binary form.
And j=8------>1000 binary form.
Let us take i!j means "i OR j" operation.
i.e., i j (i OR j).
0 1 1.
1 0 1.
0 0 0.
0 0 0.
That means 1100 is 12. and so on. Until the final step we get 12, 12, 12.
And j=8------>1000 binary form.
Let us take i!j means "i OR j" operation.
i.e., i j (i OR j).
0 1 1.
1 0 1.
0 0 0.
0 0 0.
That means 1100 is 12. and so on. Until the final step we get 12, 12, 12.
Mani said:
1 decade ago
i=4,j=8
|,&,^-these r bitwise operators so first we convert the iand j value to binary.
i=0100 j=1000
step1:
qus=i|j@j|i?
i|j=0100|1000=1100
j|i=1000|0100=1100
finally
i|j@j|i=1100&1100=1100=12
so the ans is 12 12 12
|,&,^-these r bitwise operators so first we convert the iand j value to binary.
i=0100 j=1000
step1:
qus=i|j@j|i?
i|j=0100|1000=1100
j|i=1000|0100=1100
finally
i|j@j|i=1100&1100=1100=12
so the ans is 12 12 12
Vanaja said:
1 decade ago
Binary value of 4 is 0100.
Binary value of 8 is 1000.
Using OR operation compare it we get 1100 it is equal to 12.
Again we got 12 by comparison, compare both binary values of using AND operator we got the answer.
Binary value of 8 is 1000.
Using OR operation compare it we get 1100 it is equal to 12.
Again we got 12 by comparison, compare both binary values of using AND operator we got the answer.
Ananya said:
1 decade ago
But doesn't an int store 16 bits?
Then why is everyone taking only 4 bits in hand?
Because if you consider 4 as 00000000 00000100 and 8 as 00000000 00001000 then while you XOR them it makes a difference!
Then why is everyone taking only 4 bits in hand?
Because if you consider 4 as 00000000 00000100 and 8 as 00000000 00001000 then while you XOR them it makes a difference!
Abhishek said:
1 decade ago
There is any other method available so computation will become fast.
As such that we need not to convert the number in binary first and direct get the answer.
As such that we need not to convert the number in binary first and direct get the answer.
Jeva said:
10 years ago
Another thing to notice is that of the three printed numbers the first two *have* to be the same whatever they are. Only A satisfies this.
Nilesh said:
8 years ago
@Sujithra.
The ans will be 1000.
In &(AND) operation,
1 & 1=1.
1 & 0=0.
0 & 1=0.
0 & 0=0.
The ans will be 1000.
In &(AND) operation,
1 & 1=1.
1 & 0=0.
0 & 1=0.
0 & 0=0.
Safi said:
1 decade ago
if i|j =12
and i^j=12 then
How its operation will be perform same, while both are distinct bitwise operators ?
and i^j=12 then
How its operation will be perform same, while both are distinct bitwise operators ?
Prasad said:
1 decade ago
@Kirti.
Your truth table for xor gate is wrong.
Truth table is:
A B output.
0 0 0.
0 1 1.
1 0 1.
1 1 0.
Your truth table for xor gate is wrong.
Truth table is:
A B output.
0 0 0.
0 1 1.
1 0 1.
1 1 0.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers