-
Notifications
You must be signed in to change notification settings - Fork 153
Operators
Andrew James edited this page Sep 25, 2016
·
4 revisions
There are several types of operators available in C/C++:
Note: this list is not exhaustive and some symbols have multiple operator definitions depending on the context. The * operator for example can be used for multiplication, or to de-reference a pointer. (Pointers/references will be covered later in the tutorial).
| Operator | Action | Example |
|---|---|---|
| = | Assignment | x = y |
| + | Addition | c = a+b |
| - | Subtraction | c = a-b |
| * | Multiplication | c = a*b |
| / | Division | c = a/b |
| % | Modulo (remainder after division) | rem = a%b |
| += | Add then assign |
a += b (equivalent to a= a+b) |
| -= | Subtract then assign |
a-=b (equivalent to a = a-b) |
| *= | Multiply then assign |
a*=b (equivalent to a = a*b) |
| /= | Divide then assign |
a /=b (equivalent to a = a/b) |
| ++ | Increment |
a = 0; a++; (a now is 1 ) |
| -- | Decrement |
a = 1; a--; (a is now 0) |
| operator | Action | Example |
|---|---|---|
| == | Equal to | a ==b |
| != | Not equal to | a != b |
| > | greater than | a > b |
| < | less than | a > b |
| >= | greater than or equal to | a >= b |
| <= | less than or equal to | a <= b |
| Operator | Action | Example |
|---|---|---|
| && | And | (a == b) && (b == c) |
| || | or | ` (a == b ) |
| ! | not | !( a==b ) |