1 Common operators
2assignment | increment | arithmetic | logical | comparison | member | other
3 | decrement | | | | access |
4-----------------------------------------------------------------------------
5 a = b | ++a | +a | !a | a == b | a[b] | a(...)
6 a += b | --a | -a | a && b | a != b | *a | a, b
7 a -= b | a++ | a + b | a || b | a < b | &a | ? :
8 a *= b | a-- | a - b | | a > b | a->b |
9 a /= b | | a * b | | a <= b | a.b |
10 a %= b | | a / b | | a >= b | a->*b |
11 a &= b | | a % b | | a <=> b | a.*b |
12 a |= b | | ~a | | | |
13 a ^= b | | a & b | | | |
14 a <<= b | | a | b | | | |
15 a >>= b | | a ^ b | | | |
16 | | a << b | | | |
17 | | a >> b | | | |
1// Operators are simply functions but cooler
2// E.g: The + sign is an operator, [] is an operator, you get the point
3// Which is even cooler is you can overload them
4// Means you can change their behavior
5// I can make + actually decrement (dont do this)
6int operator+(int other){
7 return *this - other;
8}
9// And make - return always 0
10int operator-(int other){ return 0; }
11// (THIS IS ANOTHER PROGRAM SO + AND - ARE NOT BROKEN ANYMORE)
12#include <iostream>
13#include <string>
14#include <stdio.h>
15#include <vector>
16// And then im gonna make a class
17class UselessClass{
18private:
19 // And have a vector of integers with a bunch of numbers
20 std::vector<int> numbers = {1, 2, 3};
21public:
22 // Then im gonna make the array index operator return the int at the index but with 5 added to the int
23 int operator[](int index){
24 return this->numbers[index] + 5;
25 }
26};
27int main(){
28 // And then
29 UselessClass a;
30 std::cout << a[0] << "\n";
31 // It will print 6
32}
1#include <stdio.h>
2int main() {
3 int var1 = 5, var2 = 5;
4
5 // 5 is displayed
6 // Then, var1 is increased to 6.
7 printf("%d\n", var1++);
8
9 // var2 is increased to 6
10 // Then, it is displayed.
11 printf("%d\n", ++var2);
12
13 return 0;
14}