Operators, Expressions, Precedence, and Type Conversion
Understand arithmetic, relational, logical, bitwise, assignment, and conditional operators along with expression evaluation and type conversion rules.
Inside this chapter
- Arithmetic and Assignment Operators
- Relational and Logical Operators
- Increment, Decrement, and Side Effects
- Type Conversion
- Bitwise Operators
- Real-World Usage Snapshot
Series navigation
Study the chapters in order for the clearest path from C basics to advanced memory, systems, debugging, and real-world development practice. Use the navigation at the bottom of each page to move smoothly through the full tutorial.
Arithmetic and Assignment Operators
int a = 10;
int b = 3;
int sum = a + b;
int product = a * b;
int quotient = a / b;
int remainder = a % b;
Integer division is especially important to understand: 10 / 3 gives 3, not 3.333..., because both operands are integers.
Relational and Logical Operators
if (age >= 18 && hasId) {
printf("Allowed\n");
}
Logical operators such as &&, ||, and ! are central to conditions. Students should also understand short-circuit behavior.
Increment, Decrement, and Side Effects
int x = 5;
int y = x++;
int z = ++x;
Post-increment and pre-increment differ in when the value changes relative to the surrounding expression. Writing overly complex expressions with side effects is a common beginner mistake and a readability problem even for experienced programmers.
Type Conversion
double result = (double) 5 / 2;
Without the cast, 5 / 2 is integer division. With the cast, the expression becomes floating-point division. Understanding implicit and explicit conversion is essential for correct calculations.
Bitwise Operators
Bitwise operations such as &, |, ^, <<, and >> are common in systems programming, flags, masks, device control, and performance-sensitive logic.
Real-World Usage Snapshot
Correct expression handling matters in protocols, embedded software, numeric logic, and state machines. Many hard-to-find bugs come from incorrect assumptions about operator precedence or type conversion.