Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » C Programming - Associativity of Operators.
Closed Thread
Old 04-02-2005, 11:12 AM   #1 (permalink)
 
True Techie

Join Date: Dec 2004

Posts: 145

Mohan Giri

Default C Programming - Associativity of Operators.

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???????????
Mohan Giri is offline  
Old 04-02-2005, 12:02 PM   #2 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

Do you mean order of operations.
()
*
/
+
-
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 04-02-2005, 12:56 PM   #3 (permalink)
 
True Techie

Join Date: Dec 2004

Posts: 145

Mohan Giri

Default

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
Mohan Giri is offline  
Old 04-03-2005, 04:30 PM   #4 (permalink)
 
Super Techie

Join Date: Mar 2005

Posts: 259

C.Ingram

Send a message via AIM to C.Ingram Send a message via Yahoo to C.Ingram
Default

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.
__________________
Christopher Ingram
Principal Consultant, Souken Group, LLC.
C.Ingram@SoukenGroup.com
(856) 392 5244 -- (866) Go Souken
C.Ingram is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On