You may know what +, &&, and = mean separately, yet still predict the wrong result when they appear in one C expression. Use a fixed method: identify the operands, group operators by precedence, apply associativity only within the same level, then check sequencing and operand types. Run that method on 5 + 2 * 3 > 10 && 8 / 4 == 2 and it settles on 1 without a single guess. Aim for a trace you can explain, not blind memorisation.
C operators: operands, results, and the main operator families
An operator is a symbol that acts on one, two, or three operands. !x is unary, a + b is binary, and condition ? yes : no is the ternary conditional operator.
With int a = 12, b = 5, the main families behave like this:
Family | Example | Result |
|---|---|---|
Arithmetic |
|
|
Relational |
|
|
Logical |
|
|
Assignment |
|
|
Conditional |
|
|
Relational and logical operators produce integer 0 or 1. Other families include bitwise, increment and decrement, address and dereference, member access, cast, sizeof, and comma operators. For a wider C-to-DSA path, follow the sequence under Coding & DSA courses.
Operator precedence in C: grouping rules from postfix to comma
Read these precedence tiers from high to low:
Tier | Operators |
|---|---|
Postfix |
|
Unary and cast |
|
Multiplicative, additive |
|
Shift, relational, equality |
|
Bitwise AND, XOR, OR |
|
Logical AND, OR |
|
Conditional |
|
Assignment |
|
Comma |
|
Binary tiers generally group left to right; unary, conditional, and assignment right to left. Thus 20 / 5 * 2 is (20 / 5) * 2 = 8, while a = b = 7 is a = (b = 7), leaving both 7.
Precedence describes parsing, not evaluation order. Parentheses show grouping but cannot make unsequenced side effects safe. Learn common tiers; parenthesise unclear intent.
Operator precedence in C: trace one mixed expression completely
Run this program:
#include <stdio.h>
int main(void) {
int result = 5 + 2 * 3 > 10 && 8 / 4 == 2;
printf("%d\n", result);
return 0;
}2 * 3 = 65 + 6 = 1111 > 10 = 18 / 4 = 22 == 2 = 11 && 1 = 1
Grouping is ((5 + (2 * 3)) > 10) && ((8 / 4) == 2). Output:
1&& evaluates left first. It evaluates the right here only because the left is true.

Arithmetic, relational, logical, and conditional operators in C
Operand types affect arithmetic. With integers, 5 / 2 gives 2. In (double)5 / 2, the cast converts 5 before division because casts are in the unary tier, so floating-point division gives 2.5.
Relational operators compare and hand back an int. With int p = 7, q = 7;, p > q is 0, p >= q is 1, and p != q is 0. The relational tier sits below both arithmetic tiers, so p + 1 > q groups as (p + 1) > q and gives 1.
Short-circuiting can guard an operation:
int num = 10, den = 0;
int safe = den != 0 && num / den > 2;den != 0 is false, so num / den is not evaluated and safe becomes 0. Bitwise & does not provide this protection.
The conditional operator selects one of two results. In int a = 14, b = 9; int max = a > b ? a : b;, max becomes 14. Parentheses remain useful when ?: appears inside a larger expression.
Bitwise operators in C: calculate with exact binary values
Let unsigned x = 12u; and unsigned y = 10u;. The rows below show the low eight bits; a real unsigned int is usually 32 bits wide, and for these two values every higher bit is 0. Review Number Systems and Base Conversions Explained if base conversion is unfamiliar.
Expression | Decimal | Eight-bit representation |
|---|---|---|
| 12 |
|
| 10 |
|
| 8 |
|
| 14 |
|
| 6 |
|
| 24 |
|
| 5 |
|
AND, OR, and XOR follow the Boolean Algebra and K-map Minimization Guide. Bitwise 12 & 10 is 8; logical 12 && 10 is 1 since both are nonzero.

Associativity, increment, assignment, and sequencing in C
Associativity settles ties inside one precedence level and nothing more. 100 / 10 / 5 groups left to right as (100 / 10) / 5 = 2; the other grouping, 100 / (10 / 5), would give 50. Assignment groups the other way, so total = count = 0 runs count = 0 first and then stores that assignment's own value in total. Neither rule fixes the order in which the operands themselves are evaluated.
Keep side effects fully separate here:
#include <stdio.h>
int main(void) {
int i = 4;
int old = i++; /* old = 4, i becomes 5 */
int now = ++i; /* i becomes 6, now = 6 */
printf("%d %d %d\n", old, now, i);
return 0;
}Postfix i++ hands back the old value and increments afterwards; prefix ++i increments first and hands back the new value. Output:
4 6 6i = i++ + ++i; has undefined behaviour because i is modified repeatedly without required sequencing. Precedence groups it, but no portable answer exists.
In int z = (a = 3, b = 4, a + b);, the comma operator runs left to right and leaves z = 7. Function-argument commas are separators.
C operator mistakes and exam-style output exercises
Parse these:
Wrong code | Actual parse or result | Repair |
|---|---|---|
| Assigns |
|
|
|
|
|
|
|
| Integer result: | Cast first for |
Predict first:
Expression | Answer |
|---|---|
|
|
|
|
|
|
At | Chained: |
After |
|
Exam setters reuse a small set of shapes: predict an output, add the parentheses that repair a misparse, catch = written where == was meant, separate bitwise & from logical &&, and recognise an expression that is undefined instead of computing one. For the full rung-by-rung ladder with an associativity column, and the a+++b tokenisation trap, read Operator Precedence and Associativity in C.
Operators and precedence in C: the short version and next step
Use four steps: mark operators, group by precedence, apply associativity within one tier, then check types and sequencing. Do not guess from surface order. Explicit parentheses document the intended grouping clearly, but do not fix unsafe side effects.
Retype the mixed-expression program, change one operator at a time, and predict the output before compiling. Explain each grouping before accepting the result. For a complete progression from operators into control flow, functions, arrays, and pointers, continue with the C Language course.




