Dart int operator-subtraction
Syntax & Examples
int.operator-subtraction operator
The `-` operator in Dart performs subtraction between two numbers.
Syntax of int.operator-subtraction
The syntax of int.operator-subtraction operator is:
operator -(num other) → numThis operator-subtraction operator of int subtraction operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | The other number to subtract. |
✐ Examples
1 Subtraction
In this example,
- We create two integer variables
num1andnum2with values 10 and 5 respectively. - We use the
-operator to perform the subtraction operation ofnum2fromnum1. - We then print the result to standard output.
Dart Program
void main() {
int num1 = 10;
int num2 = 5;
int result1 = num1 - num2;
print('Subtraction of $num2 from $num1: $result1');
}Output
Subtraction of 5 from 10: 5
2 Subtraction
In this example,
- We create two integer variables
num3andnum4with values 8 and -3 respectively. - We use the
-operator to perform the subtraction operation ofnum4fromnum3. - We then print the result to standard output.
Dart Program
void main() {
int num3 = 8;
int num4 = -3;
int result2 = num3 - num4;
print('Subtraction of $num4 from $num3: $result2');
}Output
Subtraction of -3 from 8: 11
3 Subtraction
In this example,
- We create two integer variables
num5andnum6with values -5 and -7 respectively. - We use the
-operator to perform the subtraction operation ofnum6fromnum5. - We then print the result to standard output.
Dart Program
void main() {
int num5 = -5;
int num6 = -7;
int result3 = num5 - num6;
print('Subtraction of $num6 from $num5: $result3');
}Output
Subtraction of -7 from -5: 2
Summary
In this Dart tutorial, we learned about operator-subtraction operator of int: the syntax and few working examples with output and detailed explanation for each example.