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;
}
12, 12, 12
112, 1, 12
32, 1, 12
-64, 1, 12
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
58 comments Page 5 of 6.

Karthika said:   1 decade ago
Then, which operator is used to denote "power-off" ?

Don't we use ^ ?

Tamojit Pal said:   1 decade ago
i=4 (binary-0100)
j=8 (binary-1000)
i|j&j|i...12(why)?
0100|1000=1100(by,bitwise OR operation)
1000|0100=1100(by,bitwise OR operation)
1100&1100=1100(12)(by,bitwise AND operation)

same as...i|j&j|i..12

and..
i^j...12(why)?
0100|1000=1100(by, bitwise XOR operation)
=12

Atul jain said:   1 decade ago
Thanks Vedhashree.

Alok said:   1 decade ago
Lot's of thank's all the people those who given the answer of this question.

Monica said:   1 decade ago
Thanx Mani

Prerna said:   1 decade ago
Thanx Vedashree

Selvaraj.v said:   1 decade ago
Do the bitwise operation from left to right

Binary form of 8 is 1000 and 4 is 0100

step:1 j=1000&1000=1000
step:2 i|j=0100|1000=1100
step:3 decimal value of 1100 is 12
step:4 do the same operation i|j&j|i value is=12
step:5 do the XOR operation i^j:0100^1000=1100=12
step:6 answer is 12 12 12

Vikas said:   1 decade ago
Thanks vedhashree.

Syed said:   1 decade ago
Thanks vedashree

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


Post your comments here:

Your comments will be displayed after verification.