What is arithmetic operators in DART
In this article, i am going to explain about arithmetic operators in DART.
Operators In DART
Although most of DART operators should be familiar to C and C++ developers, Here we will discuss about arithmetic operators.
- Arithmetic operators
DART supports different arithmetic operators.
Operators |
Meaning |
+ |
To perform addition operation. |
- |
To perform subtraction operation. |
* |
To perform multiplication operation. |
/ |
To perform division operation. |
-expr |
Unary negation |
~/ |
Divide, returning the integer value |
% |
Get the remainder |
++var |
Value is var+1 (Pri-increment). |
var++ |
Value is var (Post-increment). |
--var |
Value is var-1 (Pri-decrement). |
var-- |
Value is var (Post-decrement). |
Example of arithmetic operators
void main() {
int a=4,b=3;
print("Welcome in DART Operator");
print("The addition of $a and $b is ${a+b}");
print("The subtraction of $a and $b is ${a/b}");
print("The multiplication of $a and $b is ${a*b}");
print("The division of $a and $b is ${a/b}");
print("The negation of $a and $b is ${a~/b}");
print("The reminder of $a and $b is ${a%b}");
print("The pri-increment of $a is ${++a}");
print("The post-increment of $a is ${a++}");// here a value is 5 because value of a is also increse by one in pri-increment //operation.
print("The pri-decrement of $b is ${--b}");
print("The post-decrement of $b is ${b--}");// here b value is 2 because value of b is also decrese by one in pri-decrement //operation.
}
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here