C supports a variety of built-in operators that perform mathematical or logical operations on data or variables.
These categories include arithmetic, relational, logical, assignment, increment and decrement, conditional,
bitwise, and special operators. Arithmetic operators perform basic operations like addition, subtraction,
multiplication, division, and modulo division. Relational operators compare quantities, while logical operators
determine the relationship between conditions using AND, OR, and NOT. The relative precedence of these
operators determines the order in which they are evaluated.
Assignment operators assign the results of an expression to a variable using the "=" symbol. Shorthand
assignment operators are also available in C for more concise code. Increment and decrement operators (++ and
--) add or subtract 1 from operands, commonly used in loops. Conditional operators like the ternary operator "?
:", allow for conditional expressions like assigning a value based on a condition.
Special operators in C include the comma operator for linking expressions, the sizeof operator to determine the
size of operands, and pointer and member selection operators for more advanced operations. Arithmetic
expressions in C combine variables, constants, and operators to calculate values. Precedence rules dictate the
order in which operators are evaluated within an expression, with higher precedence operators evaluated first.
Each operator in C has its own precedence level and associativity, determining the order of operations within an
expression.
An example program illustrates the use of variables in expressions and their evaluation. Arithmetic expressions
without parentheses are evaluated left to right following the rules of precedence. The associativity of operators
at the same precedence level determines the order of execution. By understanding the precedence and
associativity of operators, programmers can write efficient and accurate code in C programming.