Arithmetic operators are special symbols used to perform mathematical operations in C#. The basic arithmetic operators are:
Operator | Name | Description |
---|---|---|
+ | Addition | Adds two values |
- | Subtraction | Subtracts the second value from the first |
* | Multiplication | Multiplies two values |
/ | Division | Divides the first value by the second |
% | Modulus | Returns the remainder of the division of the first value by the second |
++ | Increment | Increases the value of a variable by one |
-- | Decrement | Decreases the value of a variable by one |
If you want to learn more about Arithmetic Operators
check the Introduction to Programming Course read more
List of arithmetic operators
Addition (+)
The addition operator allows us to add two values and obtain a result. For example:
int a = 5;
int b = 3;
int result = a + b; // result will be equal to 8
Subtraction (-)
The subtraction operator allows us to subtract one value from another and obtain the result. For example:
int a = 10;
int b = 7;
int result = a - b; // result will be equal to 3
Multiplication (*)
The multiplication operator allows us to multiply two values and obtain the result. For example:
int a = 4;
int b = 6;
int result = a * b; // result will be equal to 24
Division (/)
The division operator allows us to divide one value by another and obtain the result. For example:
int a = 15;
int b = 3;
int result = a / b; // result will be equal to 5
Modulus (%)
The modulus operator allows us to obtain the remainder of the division between two values. For example:
int a = 17;
int b = 5;
int result = a % b; // result will be equal to 2