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

difference between string and array?

6 Answers  


Can we change the value of constant variable in c?

0 Answers  


Explain what is the most efficient way to store flag values?

0 Answers  


read a number & print all its devisors using c-program?

3 Answers  


write a c program that if the given number is prime, and their rearrangement(permute) of that number is also prime. Ex: Input is "197" is prime Output: 791,917,179 is also prime. Please any one tell me tha code for that

3 Answers  






What is difference between structure and union in c?

0 Answers  


pgm to find middle element of linklist(in efficent manner)

4 Answers   Huawei,


In C language, a variable name cannot contain?

0 Answers  


Does c have enums?

0 Answers  


write aprogram for There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

1 Answers   iGate, Shashi, Source Bits, Subex,


what is Array?

3 Answers  


C program to find all possible outcomes of a dice?

0 Answers  


Categories