Learn to use operators for basic mathematical calculations like addition, subtraction, multiplication, division, and modulus.
Arithmetic operators are the foundation of performing mathematical calculations in C. They are used with numeric data types like `int`, `float`, and `double` to construct expressions that compute a result. The most basic operators are addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`). These work as you would expect from standard mathematics. For example, `5 + 3` evaluates to 8, and `10.0 * 2.5` evaluates to 25.0. However, the division operator (`/`) has a special behavior when used with integers. If both operands are integers, C performs integer division, which means the fractional part of the result is discarded. For instance, `10 / 3` evaluates to 3, not 3.333. To get a floating-point result, at least one of the operands must be a floating-point type, for example, `10.0 / 3`. Another crucial arithmetic operator is the modulus operator (`%`). It yields the remainder of an integer division. For example, `10 % 3` evaluates to 1, because 10 divided by 3 is 3 with a remainder of 1. The modulus operator is incredibly useful for tasks like determining if a number is even or odd (e.g., `number % 2 == 0`), cycling through a fixed number of states, or converting units. It's important to note that the modulus operator can only be used with integer types. Understanding these operators and their nuances, especially the distinction between integer and floating-point division, is a fundamental skill required for writing correct and effective C programs.