Thread: C operators.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Learning C. JOZZY& Wakko's Avatar
    Join Date
    Nov 2009
    Posts
    59

    C operators.

    I am reading a book here that claims that there is no order of execution between * and / because they are on the same level. Is this true and does C calculate from left to right first the first class operators and then the second class operators?

    At school we used to learn it differently and the book claims it should be the same as at school so it kind of confuses me.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by JOZZY& Wakko View Post
    I am reading a book here that claims that there is no order of execution between * and / because they are on the same level. Is this true and does C calculate from left to right first the first class operators and then the second class operators?

    At school we used to learn it differently and the book claims it should be the same as at school so it kind of confuses me.
    Operators of equal precedence execute in an order defined by their associativity. * and / both associate left-to-right, so the leftmost operator conceptually executes first.

    I say conceptually, because if the compiler is able to prove that some other order would produce an equivalent result, it is allowed to reorder the operations. But the result will always be the same as if the operators executed in the defined order.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Boolean Operators...
    By Nean in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2009, 02:31 AM
  2. Logical Operators in C++
    By Flecto in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2009, 07:17 AM
  3. Bolean Operators hurt my head. (Trouble understanding) :(
    By Funcoot in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2008, 07:42 PM
  4. operators???
    By arjunajay in forum C++ Programming
    Replies: 11
    Last Post: 06-25-2005, 04:37 AM
  5. Operators
    By George in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 07:35 PM