Operators are the foundation of any programming language. They are symbols that helps us to perform specific mathematical and logical computations.
There are seven classifications of operators in C++. They are:
- Logical (&&, ||, !)
- Relational (==, !=, <, >, <=, >=)
- Arithmetic (+, -, *, /, %)
- Assignment (=, +=, -=, *=, /=, %=)
- Unary (++, --)
- Bitwise (&, |, <<, >>, ~, ^)
- Ternary (?:)
Some of these you probably already know. Others you will be required to learn in this class, and others yet will not be required. The following video will review the arithmetic operators, then cover the assignment (and unary) operators.
Occasionally while looking at code, you'll see the unary operators used in an odd way. This video explains what's happening.
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
Consider the following code:
int i = 7;
i++;
i /= 2;
i--;
std::cout << "The value of i is: " << i;
- What would print to the console? The value of i is: 3