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.
Vikas said:
1 decade ago
Thanks vedhashree.
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
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
Prerna said:
1 decade ago
Thanx Vedashree
Monica said:
1 decade ago
Thanx Mani
Alok said:
1 decade ago
Lot's of thank's all the people those who given the answer of this question.
Atul jain said:
1 decade ago
Thanks Vedhashree.
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
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
Karthika said:
1 decade ago
Then, which operator is used to denote "power-off" ?
Don't we use ^ ?
Don't we use ^ ?
Abinandank said:
1 decade ago
Binary value of 8 is 1000 and 4 is 0100
consider i|j(An OR operation)
so j|y yields the same 1100
if u perform i|j & j|i
1100
1100 &
----
1100
----
1100 is equivalent to decimal 12
for printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
ans: 12 12 i=1000
j=0100 ^( see ex-or truth table) ------
1100 equiv to decimal 12
Hence 12 12 12
consider i|j(An OR operation)
Truth table
1000 val1 val2 ans(OR)ans(AND)ans(XOR)
0100 0 0 0 0 0
---- 0 1 1 0 1
1100 1 0 1 0 1
---- 1 1 1 1 0
so j|y yields the same 1100
if u perform i|j & j|i
1100
1100 &
----
1100
----
1100 is equivalent to decimal 12
for printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
ans: 12 12 i=1000
j=0100 ^( see ex-or truth table) ------
1100 equiv to decimal 12
Hence 12 12 12
Ramdas said:
1 decade ago
Given data is int i=4, j=8;
i=4=0100
j=8=1000
|-> is bit wise OR
& -> is bit wise AND
^ -> is bit wise XOR
in sop(Structure Oriented Programing)Languages like c and oops(Object Oriented Programming)Languages like c++ and java the evaluation order is left to right
value of i|j&j|i
so first we have to calculate i|j
i=0100
j=1000
--------
1100=i|j
1000=j
---------
1000=i|j&j
0100=i
--------
1100=i|j&j|i=12
***************
next we have to calculate i^j
i=0100
j=1000
------
1100=i^j=12
so ans is 12,12,12
i=4=0100
j=8=1000
|-> is bit wise OR
& -> is bit wise AND
^ -> is bit wise XOR
in sop(Structure Oriented Programing)Languages like c and oops(Object Oriented Programming)Languages like c++ and java the evaluation order is left to right
value of i|j&j|i
so first we have to calculate i|j
i=0100
j=1000
--------
1100=i|j
1000=j
---------
1000=i|j&j
0100=i
--------
1100=i|j&j|i=12
***************
next we have to calculate i^j
i=0100
j=1000
------
1100=i^j=12
so ans is 12,12,12
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers