Logo

Developer learning path

Rust

Operators in Rust

Operators

99

#description

In Rust, operators are special symbols or keywords that are used to perform arithmetic, logical, relational, and bitwise operations on different types of data. Rust provides a wide variety of operators such as binary operators, unary operators, and compound operators.

Binary operators are operators that work on two operands.

Some examples of binary operators in Rust are:

  • Addition operator (+): used for adding two numbers or concatenating two strings.
  • Subtraction operator (-): used for subtracting one number from another.
  • Multiplication operator (*): used for multiplying two numbers.
  • Division operator (/): used for dividing one number by another.
  • Modulus operator (%): used for obtaining the remainder after a division operation.

Unary operators are operators that work on a single operand.

Some examples of unary operators in Rust are:

  • Negation operator (-): used for negating a number.
  • Logical NOT operator (!): used for negating a boolean value.

Compound operators are shorthand notations for performing arithmetic operations and assigning the result back to the variable.

Some examples of compound operators in Rust are:

  • Addition and assignment operator (+=): used for adding a value to a variable and assigning the result back to the variable.
  • Subtraction and assignment operator (-=): used for subtracting a value from a variable and assigning the result back to the variable.
  • Multiplication and assignment operator (*=): used for multiplying a value to a variable and assigning the result back to the variable.
  • Division and assignment operator (/=): used for dividing a value from a variable and assigning the result back to the variable.

Knowing how to use operators in Rust is essential for performing various operations on different types of data.

March 27, 2023

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.