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.
Kavi said:
10 years ago
Anyone can explain?
What is the difference between i&j and i&&j?
What is the difference between i&j and i&&j?
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.
Earl said:
8 years ago
Thanks to all your explanations.
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.
Madhu said:
1 decade ago
I can't understand what is in printf statement. Can you explain?
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.
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.
Sujithra said:
9 years ago
What will be the answer when 1100&1000 occur in a program? please explain in detail.
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!
Raji said:
8 years ago
Thank you to all your answers and explanation.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers