Arithmetic operators are used to perform mathematical operations in Dart. As we all know every programming language has their own Arithmetic operators so on the Dart. There are basically 9 Arithmetic operators available in Dart language. In today’s tutorial we would discuss them all with a basic example so you’ll know how they works in Dart. So in this tutorial we would learn about Flutter Dart List of All Arithmetic Operators with Example Tutorial.
Contents in this project Flutter Dart List of All Arithmetic Operators with Example:
There are mainly 9 Arithmetic operators in dart but when we would learn about them, There’ll be 11 of them total. So below is the list of all arithmetic operators in Dart.
S.No. | Operator | Name |
1 | + | Add (Plus) |
2 | – | Subtract (Minus) |
3 | * | Multiply |
4 | / | Divide |
5 | ~/ | Divide Which returns result in Near Integer value |
6 | % | Returns Remainder of Integer Division ( Modulo ) |
7 | ++variable | +1 (Increment variable before gets its value) |
8 | variable++ | +1 (Increment variable after gets its value) |
9 | –variable | -1 (Decrement variable before gets its value) |
10 | variable — | -1 (Decrement variable after gets its value) |
11 | -expr | Unary Minus(Negation)-Used to reverse sign of given expression |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
void main() { var a, b; print(2 + 3); // Result = 5 print(5 - 2); // Result = 3 print(2 * 3); // Result = 6 print(5 / 2); // Result = double - 2.5 print(5 ~/ 2); // Result = Int - 2 print(5 % 2); // Remainder = - 1 a = 0; b = ++a; // Increment a value before b gets its value. print(a); // Result = 1 a = 0; b = a++; // Increment a AFTER b gets its value. print(b); // Result Value of b = 0 and Value of a = 1 a = 0; b = --a; // Decrement a value before b gets its value. print(a); // Result is -1 a = 0; b = a--; // Decrement a value AFTER b gets its value. print(b); // Result is 0 } |
Output:
Also Read:
Flutter Solve Your app is not using AndroidX Build Migration Error
Flutter Solve Project Requires A Newer Version of the Kotlin Gradle Plugin Error
[Solved] Flutter command line-tools component is missing Error
Generate release-key.keystore File in Flutter For Signed APK
Flutter Column MainAxisAlignment Properties Explained with Example