Learn C - C Operator Precedence

The following table shows the order of precedence for all the operators in C, from highest at the top to lowest at the bottom.

1( )Parenthesized expression
1[]Array indexer
1.Member selection by object
1->Member selection by pointer
1++ --Postfix increment and prefix decrement
2+ -Unary + and -
2++ --Prefix increment and prefix decrement
2! ~Logical NOT and bitwise complement
2*Dereference Pointer
2sizeofSize of operator
2(type)Explicit cast
3* / %Multiplication and division and remainder
4+ -Addition and subtraction
5<< >>Bitwise shift left/right
6< < =Less than and less than or equal to
6> >=Greater than and greater than or equal to
7== !=Equal to and not equal to
8&Bitwise AND
9^Bitwise exclusive OR
10|Bitwise OR
11&&Logical AND
12||Logical OR
13?:Conditional operator
14+= -=Addition assignment and subtraction assignment
14/= *=Division assignment and multiplication assignment
14%=Modulus assignment
14<<= >>=Bitwise shift left/right assignment
14&= |=Bitwise AND/OR assignment
14^=Bitwise exclusive OR assignment
15,Comma operator


The following code shows the usage of Operator Precedence.

#include <stdio.h>
int main(void) {
      int top, score;

      top = score = -(3 + 5) * 6 + (4 + 3 * (2 + 3));
      printf("top = %d, score = %d\n", top, score);

      return 0;

The code above generates the following result.