When evaluating order of operations like a problem x = a + (b - c) / (d - e * f). Do you evaluate left to right or right to left? Thanks for your time guys.

-Will

Printable View

- 12-06-2002C-DuddleyOrder of Operations
When evaluating order of operations like a problem x = a + (b - c) / (d - e * f). Do you evaluate left to right or right to left? Thanks for your time guys.

-Will - 12-06-2002samps005
as far as I know it is always left to right for all infix notation

- 12-06-2002Polymorphic OOPQuote:

*Originally posted by samps005*

**as far as I know it is always left to right for all infix notation**

Only a few operators guarantee order, which include

||

&&

so that you can be certain of the short-circut evaluation.

with addition, subtraction, etc. it's up to the compiler to choose order.

so in

a + (b - c) / (d - e * f).

The compiler can do

b - c

first, or it can do

( d - e * f )

first. It's not defined by the standard. - 12-06-2002Mister C
I think you confused him... anyway it is on page 200 of the The C Programming Lang book (K & R).