Assignment Variable operator = Expression Variable = Variable operator (Expression) x+=y+1 x=x+(y+1) a=a+1a+=1 a=a-1a-=1 a=a*(n+1)a*=n+1 a=a/(n+1)a/=n+1 a= a% ba%= b Increment Decrement ++m, m++m = m+1 ; or m+=1; - -mm = m-1 ; or m-=1; y=++m (prefix) increase the value of m and assign it to y. y=m++ (postfix) assign the value m to y then increment m.
Conditional Operators Expression 1 ? Expression 2 : Expression 3 x=(a>b) ? a : b; If expression 1 is true then the value is expression 2 else the value is expression 3 If a> b then x=a else x=b
&Bitwise AND |Bitwise OR ^Bitwise exclusive OR <>Shift right Bitwise Manipulating data at bit level Bitwise operators The comma operators v = (x=10,y=5, x + y); x=10; y=5; v= x + y;
Arithmetic Expression Algebraic expression C expression
Precedence of Arithmetic operators 1.An arithmetic expression is evaluated from left to right. 2.High priority operators ( * / % ) are evaluated first. 3.Low priority operators ( + - ) are evaluated next. x= 9 – 12 / 3 + 3 * 2 - 1; 46 5 11 10
Parenthesized expression 1.The parenthesized expressions change the evaluation priority. 2.The innermost parentheses have the highest priority. 3.The outermost parentheses have the lowest priority. 4.The nesting levels of intermediate parentheses determine their priority. 5.Un-parenthesized expressions within parentheses are evaluates according to the rules described for un parenthesized expressions. z = 9 - ( 18 / (3 + 3 * 2 ) * 2 ) - 1; 6 9 2 4 5 4
Type conversions in expressions Implicit Type Conversion short and char are automatically converted to int. If one operand is long double then the other operand is converted to long double and the result is in long double. else If one operand is double then the other operand is converted to double and the result is in double. else If one operand is float then the other operand is converted to float and the result is in float. else If one operand is unsigned long int then the other operand is converted to unsigned long int and the result is in unsigned long int. else If one operand is long int and the other is unsigned int, then – If unsigned int can be converted to long int, then the result will be long int – else both will be unsigned long int. else If one operand is long int then the other operand is converted to long int and the result is in long int. else If one operand is unsigned int then the other operand is converted to unsigned int and the result is in unsigned int. Explicit Type Conversion (Type name) expression (int) a+b (double) x/y Operator Associativity Decides the order in which multiple occurrences of the same level operators are applied.