Order of Operations

This is a discussion on Order of Operations within the C Programming forums, part of the General Programming Boards category; When evaluating order of operations like a problem x = a + (b - c) / (d - e * ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    11

    Order 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

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    27
    as far as I know it is always left to right for all infix notation

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by samps005
    as far as I know it is always left to right for all infix notation
    It's actually not defined, believe it or not!

    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.

  4. #4
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    I think you confused him... anyway it is on page 200 of the The C Programming Lang book (K & R).
    Mr. C: Author and Instructor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of operations question
    By GuitarNinja in forum C++ Programming
    Replies: 4
    Last Post: 04-11-2009, 06:14 AM
  2. Order of Operations Question
    By chix/w/guns in forum C++ Programming
    Replies: 35
    Last Post: 07-17-2004, 03:38 AM
  3. order of operations...
    By jverkoey in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2004, 11:38 PM
  4. order of operations when programming in API
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2002, 04:34 PM
  5. order of operations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 10-31-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21