More C expressions ANSI-C
Increment and decrement operators Expression Expression Value Effect i++ value of i before increment i is incremented ++i value of i after increment i is incremented Examples: int i = 0; int j; j = i++; /* j is 2 and i is 3 */ j = ++i; /* j is 4 and i is 4 */
Assigment Expression Assignment is an expression, thus it can appear anywhere an expression can appear. The value of an assigment expression is the same as the value of its right hand side. if ( x = (y + 10)) statement;
Conditional expression Syntax: expr1 ? exp2 : exp3 This is equivalent to write: if (expr1) exp2; else expr3; Example: y = (x>0) ? x = -x;
(and <<= >>= &= ^= |=, not covered) In general a op= b; Assignment Operators += -= *= %= (and <<= >>= &= ^= |=, not covered) In general a op= b; It’s (almost) equivalent to: a = a op (b); Example: int x = 5; int y = 10; x -= y + 3; x = x – (y + 3);