Arithmetic and Relational Operators
Learn about different arithmetic and relational operators in Solidity.
We'll cover the following
In this lesson, we’ll explore two crucial categories of operators: arithmetic and relational. We’ll focus on arithmetic operators, which enable us to perform various mathematical computations in our smart contracts. Additionally, we’ll explore relational operators, allowing us to compare values and make logical assessments.
Arithmetic operators
To conduct mathematical or arithmetic operations in Solidity, we can employ a set of operators designed for this purpose. The following arithmetic operators are available in Solidity:
Addition (
+
): This is used to add values together.Subtraction (
-
): This is used to subtract one value from another.Multiplication (
*
): This is used to multiply values.Division (
/
): This is used to divide one value by another.Modulus (
%
): This computes the remainder of a division operation.Decrement (
--
): This decrements the value of a variable by 1.Increment (
++
): This increments the value of a variable by 1.
Here’s a sample Solidity contract that demonstrates the use of these arithmetic operators:
Get hands-on with 1400+ tech skills courses.