Subtracting two numbers in Rust is simple and can be achieved using the -
operator. Here's an example:
main.rs117 chars7 lines
In this example, we declare two integer variables num1
and num2
, both initialized with values 10 and 5 respectively. We subtract num2
from num1
and store the result in a variable named result
. Finally, we print the value of result
which is 5
.
The output of the program will be:
main.rs10 chars2 lines
Note that both num1
and num2
are of type i32
(32-bit signed integer) in this example. The resulting value of the subtraction operation will also be of type i32
.
gistlibby LogSnag