operators c++ code example

Example 1: c++ .* operator

The .* operator is used to dereference pointers to class members.

Example 2: operator c++

Common operators
assignment | increment | arithmetic |  logical | comparison | member | other
		   | decrement |            |		   |		    | access |
-----------------------------------------------------------------------------                            
  a = b    |    ++a    |     +a	    |	 !a	   |   a == b   |  a[b]  | a(...)
  a += b   |	--a	   |     -a		|  a && b  |   a != b   |   *a   |  a, b
  a -= b   |	a++	   |   a + b	|  a || b  |   a < b    |   &a   |  ? :
  a *= b   |	a--	   |   a - b	|	       |   a > b    |  a->b  |
  a /= b   |		   |   a * b	|	       |   a <= b	|  a.b   |
  a %= b   |		   |   a / b	|		   |   a >= b	|  a->*b |
  a &= b   |		   |   a % b	|		   |   a <=> b	|  a.*b  |
  a |= b   |		   |     ~a		|		   |		    |		 |
  a ^= b   |		   |   a & b	|		   |   		    |		 |
  a <<= b  |		   |   a | b	|		   |			|		 |
  a >>= b  |		   |   a ^ b	|		   |			|		 |     
   		   |		   |   a << b	|		   |			|		 |  
     	   |		   |   a >> b	|		   |			|		 |

Example 3: how does ++operator works in c++

#include <stdio.h>
int main() {
   int var1 = 5, var2 = 5;

   // 5 is displayed
   // Then, var1 is increased to 6.
   printf("%d\n", var1++);

   // var2 is increased to 6 
   // Then, it is displayed.
   printf("%d\n", ++var2);

   return 0;
}

Example 4: opperanf >> c++

packet >> rec1.getPosition().x >> rec1.getPosition().y;

Tags:

Cpp Example