Why does the following program works, and what is ^+ operator ?
int main()
{
int a = 10;
int b = 20;
int c;
c = a ^+ b;
printf("Value ===> %d", c);
return 0;
}
Just in case you don't understand, the '+' is NOT addition here. It
represents the sign of the number, i.e. "positive b", or 1 * b, if it
helps you to think of it that way. In other words:
c = a ^+ b;
c = a ^ (+b);
c = a ^ (1 * b);
c = a ^ b;
If you used "c = a ^- b," it would be similar, except that you would
be performing the bitwise XOR operation on the negative value of 'b'.
Obviously the sign of the variable doesn't correspond directly to the
sign of the value. After all, if b==-4 then it would be the same as
the following:
c = a ^+ (-4);
c = a ^ (-4);
If you used ^-, it would be the following:
c = a ^- (-4);
c = a ^ -(-4);
c = a ^ 4;
I hope this helps!