From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Arithmetic operations

Arithmetic operations - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Arithmetic operations

- [Instructor] Rust provides the standard set of arithmetic operations you can expect from any programming language, including addition, subtraction, multiplication, division and the modulo operator. The code shown here demonstrates the addition operator which we've already used in a previous video. After initializing the variables "a" and "b" for the integer values 10 and three, line four uses the plus symbol to add those variables together and then the equals symbol which is the assignment operator, assigns the result to the variable "c." When I run this program, the print line macro on line five says that the value of c is 13. Now, changing the plus symbol on line four to a minus symbol will subtract b from a. When I run the program now, we see that 10 minus three is seven. If we want to multiply the variables a and b, we can use the asterisk symbol, which is the multiplication operator. Running that program…

Contents