This document describes C operators and their precedence. It lists C operators from highest to lowest precedence and shows whether each associates from the left or right. Functions, arrays, structs, increment/decrement, unary operators and casts have high precedence while assignment operators have low precedence. Comparison operators like == and != are evaluated before logical operators like && and ||.
This document describes C operators and their precedence. It lists C operators from highest to lowest precedence and shows whether each associates from the left or right. Functions, arrays, structs, increment/decrement, unary operators and casts have high precedence while assignment operators have low precedence. Comparison operators like == and != are evaluated before logical operators like && and ||.
Description Operator Associates from the Precedence
Function expr () left High
Array expr [] (Evaluated first) struct indirection -> struct member . Incr/decr ++ -- right One’s complement ~ Unary not ! Address & Dereference * Cast ( type ) Unary plus + Unary minus - Size in bytes sizeof Multiplication * left Division / Modulus % Addition + Subtraction - Shift Left << Shift Right >> Less than < Less than or equal <= Greater than > Greater than or equal >= Equal == Not equal != Bitwise and & Bitwise exclusive or ^ Bitwise inclusive or | Logical and && Logical or || Conditional ?: right Assignment = %= += *= /= >>= <<== &= ^= |= (Evaluated last) Comma , left Low