Operators are special symbols or keywords in C++ that perform operations on variables and values. They form the basis of all expressions and calculations in C++.
Used to perform basic mathematical operations.
| Operator | Description | Example |
|---|---|---|
| + | Addition | a + b |
| - | Subtraction | a - b |
| * | Multiplication | a * b |
| / | Division | a / b |
| % | Modulus (remainder) | a % b |
Used to compare two values or variables. Result is either true (1) or false (0).
| Operator | Description | Example |
|---|---|---|
| == | Equal to | a == b |
| != | Not equal to | a != b |
| < | Less than | a < b |
| > | Greater than | a > b |
| <= | Less than or equal to | a <= b |
| >= | Greater than or equal to | a >= b |
Used to combine multiple conditions and return boolean results.
| Operator | Description | Example |
|---|---|---|
| && | Logical AND (true if both conditions true) | (a > 5) && (b < 10) |
| || | Logical OR (true if at least one condition true) | (a == 5) || (b == 10) |
| ! | Logical NOT (inverts the condition) | !(a == b) |
Used to assign values to variables.
| Operator | Description | Example |
|---|---|---|
| = | Assign | a = 5 |
| += | Add and assign | a += 3 (same as a = a + 3) |
| -= | Subtract and assign | a -= 2 (same as a = a - 2) |
| *= | Multiply and assign | a *= 4 (same as a = a * 4) |
| /= | Divide and assign | a /= 5 (same as a = a / 5) |
| %= | Modulus and assign | a %= 3 (same as a = a % 3) |
Used to increase or decrease a variableβs value by 1.
| Operator | Description | Example |
|---|---|---|
| ++ | Increment by 1 | ++a or a++ |
| -- | Decrement by 1 | --a or a-- |
?: Used as a shortcut for if-else conditions.condition ? expression1 : expression2;&, |, ^, ~, <<, >>).sizeof(int)Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!