Erle Robotics C++ GitBook

Operators

We can perform arithmetic calculations with operators. Operators act on expressions to form a new expression. For example, we could replace "Hello, world!\n" with (4 + 2) / 3, which would cause the program to print the number 2. In this case, the + operator acts on the expressions 4 and 2 (its operands).

Operator types:

  • Mathematical: +, -, *, /, and parentheses have their usual mathematical meanings, including using - for negation. % (the modulus operator) takes the remainder of two numbers: 6 % 5 evaluates to 1.

  • Logical: used for “and,” “or,” and so on. More on those in the next lecture.

  • Bitwise: used to manipulate the binary representations of numbers.