Operators Precedence and Associativity in C Programming

In C Programming, each and every operator has a special precedence which is associated with it. There are various levels of precedence.

This precedence is especially used to determine the evaluation of expression which has more than one operator in it. The operators which has higher precedence are executed first and vice-versa. Operators which have same precedence level are evaluated from left to right. It is dependant on it’s level. This feature is well known as ‘Associativity of an operator.’

Associativity	Operator	Description
Left to Right	()		Function
		[]		Array
		-->		Pointer to member
		.		Structure
Right to left	-		Unary Minus
		+		Unary Plus
		++ / --		Increment/Decrement
		~		One's Complement
		&		Address of
		(type)		Type casting
		Sizeof		Size (in bytes)
		!		Logical Not
		*		Pointer reference
Left to Right	*		Multiplication
		/		Division
		%		Modulus
Left to Right	+		Addition
		-		Subtraction
Left to Right	<< Left Shift >>		Right Shift
Left to Right	<		Less than
		<= Less than or equal to >		Greater than
		>=		Greater than or equal to
Left to Right	==		Equality
		!=		Not Equal to
Left to Right	&		Bitwise AND
Left to Right	^		Bitwise XOR
Left to Right	|		Bitwise OR
Left to Right	&&		Logical AND
Left to Right	||		Logical OR
Left to Right	? :		Conditional Operator
Right to Left	=  *=  +=	Assignment
Left to Right	,		Comma

Fig.: Precedence and Associativity of Operators in C Language

Leave A Comment

Your email address will not be published. Required fields are marked *