C Programming - Associativity of Operators.

Status
Not open for further replies.

Mohan Giri

In Runtime
Messages
144
Hello Everyone,
How are you? In C Programming how associativity of operators are implemented. I mean how to identify left operand is unambiguous and right operand is unambiguous????

for example,

int on,act=1,ink=4;
float tig=3.2;
on=ink*act/2+3/2*act+2+tig;

If I evaluate this expression manually, I am getting different answer. I f evaluate using C compiler I am getting different answer. Anybody can help me???????????
 
Yes. If the expression doesn't contain paranthesis and two equal priority operators come next to next how system will execute the expresson.

For Example,


int on,act=1,ink=4;
float tig=3.2;
on=ink*act/2+3/2*act+2+tig;

ink*act/2 and 3/2*act
 
This is something that has never come up for me. I always teach to use parenthesis explicitly. That said, I belive its just left to right for equal priority operators.
 
Status
Not open for further replies.
Back
Top Bottom