problem in understanding the statement in c languagee

Status
Not open for further replies.

abhishekdixit

Full Member level 2
Joined
Dec 30, 2011
Messages
124
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
India
Visit site
Activity points
2,182
hello,
i have seen a c program in a article, in which a term
Code:
pwr_on_led=AYES^AYES;
is used.
here pwr_on_led is a variable & AYES=1. but here i am unable to understand to the meaning of expression"AYES^AYES;". in this expression what is the purpose of the symbol"^".
please help me..


with regards,
Abhishek Dixit
 

It means XOR. Exclusive ORing something with itself toggles it.

Keith

- - - Updated - - -

http://en.m.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
 

Let me clarify: it is bitwise XOR, and the result of Exclusive ORing something with itself is always 0.
So, normally the expression AYES^AYES returns a zero value of the same type as AYES.
In other words, it is equivalent to pwr_on_led=0;

N.B.: I said normally because there can be some exceptions. For instance, if AYES is defined as a funcion with a directive like this:
#define AYES somefunction()
and each invocation returns different values. But situations like these should be avoided.

Regards

Z
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…