C++ Operators
Computers process data! They read it from the keyboard, store it in variables (or constants), display it on the screen. And they also perform various operations with it. We are used to performing arithmetic operations (additions, subtractions, etc.), but in C++ there are many other operations. An operation consists of operands and an operator. Operands are the data on which operations are performed, and the operator is the symbol that determines what operation is performed with the operands.
1. Arithmetic Operators
These operators are used to perform basic mathematical operations.
- Addition(+): a + b
- Subtraction(-): a - b
- Multiplication(*): a * b
- Division(/): a / b
- Modulo(%): a % b (remainder of integer division)
2. Assignment Operators
These operators are used to assign values to variables.
- Simple Assignment(=): a = b
- Addition Assignment(+=): a += b (equivalent to a = a + b)
- Subtraction Assignment(-=): a -= b (equivalent to a = a - b)
- Multiplication Assignment(*=): a *= b (equivalent to a = a * b)
- Division Assignment(/=): a /= b (equivalent to a = a / b)
- Modulo Assignment (%=): a %= b (equivalent to a = a % b)
3. Increment and Decrement Operators
These operators are used to increase or decrease the value of a variable by 1.
- Increment(++):
- Decrement(--):
4. Relational Operators
These operators are used to compare two values.
- Equality(==): a == b
- Inequality(!=): a != b
- Less than(<): a < b
- Greater than(>): a > b
- Less than or equal(<=): a <= b
- Greater than or equal(>=): a >= b
5. Logical Operators
These operators are used to perform logical operations.
- Logical AND(&&): a && b
- Logical OR(||): a || b
- Logical NOT(!): !a