Arithmetic Operators in C
Arithmetic operators in C are used to perform basic mathematical calculations. These operators work on numeric operands such as integers and floating-point numbers.
Addition Operator (+)
The addition operator is used to add two operands and return their sum.
Example: int sum = a + b;
Subtraction Operator (-)
The subtraction operator subtracts the second operand from the first operand.
Example: int diff = a - b;
Multiplication Operator (*)
The multiplication operator multiplies two operands.
Example: int product = a * b;
Division Operator (/)
The division operator divides the numerator by the denominator.
Example: int result = a / b;
Note: Integer division truncates decimal values.
Modulus Operator (%)
The modulus operator returns the remainder after division. It works only with integer operands.
Example: int remainder = a % b;
Common Mistakes with Arithmetic Operators
- Dividing a number by zero causes runtime error
- Using modulus operator with float values
- Expecting decimal result from integer division
- Overflow when result exceeds data type limit
Codecrown