What will be the output of the following pseudocode?
Initialize Integer x, y, z Set y = 1, x = 2 z = x ^ y Print z
(A)
1
(B)
2
(C)
4
(D)
3
Answer: (D)
Explanation:
Firstly variables x, y, and z are initialized, then y and x are assigned values 1 and 2 respectively.
Now z is assigned the value of x XOR y i.e. 1 ^ 2 = 3. Since all bits in 1 and 2 are exclusive so the XOR will be equal to 1 OR 2 i.e. 3
Quiz of this Question
Please comment below if you find anything wrong in the above post
Article Tags :
Uncategorized
Recommended Articles