C | Operators | Question 22

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
int main()
{
  int a = 2,b = 5;
  a = a^b;
  b = b^a;
  printf("%d %d",a,b);
  return 0;
}

chevron_right


(A) 5 2
(B) 2 5
(C) 7 7
(D) 7 2


Answer: (D)

Explanation: ^ is bitwise xor operator.

a = 2 (10)
b = 5 (101)

a = a^b (10 ^ 101) = 7(111)
b = a^b (111 ^ 101) = 2(10)

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


3


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.