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) → num

This operator-subtraction operator of int subtraction operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe other number to subtract.


✐ Examples

1 Subtraction

In this example,

  1. We create two integer variables num1 and num2 with values 10 and 5 respectively.
  2. We use the - operator to perform the subtraction operation of num2 from num1.
  3. 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,

  1. We create two integer variables num3 and num4 with values 8 and -3 respectively.
  2. We use the - operator to perform the subtraction operation of num4 from num3.
  3. 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,

  1. We create two integer variables num5 and num6 with values -5 and -7 respectively.
  2. We use the - operator to perform the subtraction operation of num6 from num5.
  3. 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.