C++ Basics (Part 2)

Operators



Assignment Operator

Arithmetic Operators

Name Symbol Arity Usage
Add + binary x + y
Subtract - binary x - y
Multiply * binary x * y
Divide / binary x / y
Modulus % binary x % y
Minus - unary -x

Operator precedence

Example of basic arithmetic operations
 

Some short-cut assignment operators (with arithmetic)

 v += e; means v = v + e; v -= e; means v = v - e; v *= e; means v = v * e; v /= e; means v = v / e; v %= e; means v = v % e; 

Increment and Decrement Operators

 ++x;	// pre-increment (returns reference to new x) x++;	// post-increment (returns value of old x)	// shortcuts for x = x + 1 --x;	// pre-decrement x--; // post-decrement	// shortcuts for x = x - 1 

Automatic Type Conversions

Explicit type conversions (casting)