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

what is the different between data structure and data type?

1 Answers   Ignou,


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

0 Answers  


How will you write a code for accessing the length of an array without assigning it to another variable?

0 Answers  


Write a program to compute the following 1!+2!+...n!

4 Answers  


Write a C program to count the number of email on text

0 Answers  






which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )

1 Answers   C DAC,


Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

3 Answers  


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

3 Answers   ME, pspl,


f() { int a=2; f1(a++); } f1(int c) { printf("%d", c); } c=?

7 Answers   Geometric Software,


What are local and global variables?

3 Answers  


What is the difference between null pointer and wild pointer?

0 Answers  


How. To pass the entrance test

1 Answers   Tech Mahindra,


Categories