Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The EvaluationOrder/Precedence of C/C++ Operators.

20 views
Skip to first unread message

Jeff-Relf.Me

unread,
May 31, 2017, 3:30:17 PM5/31/17
to
The Evaluation Order of these expressions are UnDefined/SemiRandom:

  i = ++i + i++ ;     i = i++ + 1 ;             Array[ i ] = i++ ;
  Func( ++i, ++i );   Func( i = -1, i = -1 );   Func( i, i++ );

  http://en.cppreference.com/w/c/language/eval_order

The middle part of a Conditional Expression ( between ? and : )
is parsed as if parenthesized; for example:

  int rv, zz ;

  zz = 1, rv = zz ? zz = 1, 2 : zz = 3, 6 ;
  printf( L"%d and %d", rv, zz );  //  Prints: " 2 and 1 ".

  zz = 0, rv = zz ? zz = 1, 2 : zz = 3, 6 ;
  printf( L"%d and %d", rv, zz );  //  Prints: " 3 and 3 ".

  http://en.cppreference.com/w/c/language/operator_precedence

Precedence of C Operators:

    Associativity                                                     
  ( Left to right )     Category         Operator                         
  -----------------   ---------------  ----------------------------------------------
                        Postfix Unary    Func()  []  ->  .  ++  --
    Right to left       Prefix  Unary    +  -  !  ~  ++  --  (type)  *  &  sizeof 
                        Multiplicative   *  /  %      
                        Additive         +  -        
                        Shift            <<  >>      
                        Relational       <  <=  >  >=  
                        Equality         ==  !=      
                        Bitwise AND      &          
                        Bitwise XOR      ^          
                        Bitwise OR       |          
                        Logical AND      &&         
                        Logical OR       ||         
        N/A             Conditional      Bool ? True : False              
    Right to left       Assignment       =  +=  -=  *=  /=  %=  >>=  <<=  &=  ^=  |=
                        Comma            ,

  http://en.cppreference.com/w/c/language/operator_precedence
0 new messages