what is the use of operator ^ in C ? and how it works?

Answers were Sorted based on User's Feedback



what is the use of operator ^ in C ? and how it works?..

Answer / vinay sachan

exclusive OR ^ is a bitwise operator known as (left assoc).

expr1 ^ expr2

ex.

0x12 ^ 0x58

returns 0x4A (the set bits in the result are those that are set in either 0x12 or 0x58, but not set in both).

Is This Answer Correct ?    7 Yes 0 No

what is the use of operator ^ in C ? and how it works?..

Answer / rahul mathur

^ is a exclusive OR bitwise operator.

We can use this "^" operator for swaping two values without
using third variable and without using +, - operator as
shown below:

void xorSwap (int *x, int *y) {
if (x != y) {
*x ^= *y;
*y ^= *x;
*x ^= *y;
}
}

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Interview Questions

#include<stdio.h> main() { int a=1; int b=0; b=++a + ++a; printf("%d %d",a,b); }

7 Answers   Infosys,


Explain how do you list a file’s date and time?

0 Answers  


What is the use of clrscr?

0 Answers  


What does typeof return in c?

0 Answers  


Is it better to use a macro or a function?

0 Answers  






why TCS selected more student in the software field from all institution.

5 Answers   TCS,


Why array starts with index 0

2 Answers  


Whats s or c mean?

0 Answers  


a character variable can at a time store a) 1 character b) 8 characters c) 254 characters d) none of the above

3 Answers  


Can I initialize unions?

0 Answers  


write a program to generate address labels using structures?

0 Answers   SJC,


write a c program to find largest of three numbers using simple if only for one time.

1 Answers  


Categories