Prec/Ass Operator Description Example
Prec/Ass Operator Description Example
Operator
Description
Example
1 None
:: ::
::g_nGlobalVar = 5; Class::m_nMemberVar = 5;
Parenthesis Function call Implicit assignment Array subscript Member access from object Member access from object ptr Post-increment Post-decrement Run-time type information Cast away const Run-time type-checked cast Cast one type to another Compile-time type-checked cast
(x + y) * 2; Add(x, y); int nValue(5); aValue[3] = 2; cObject.m_nValue = 4; pObject->m_nValue = 4; nValue++; nValue; typeid(cClass).name(); const_cast<int*>(pnConstValue); dynamic_cast<Shape*>(pShape); reinterpret_cast<Class2>(cClass1); fValue = static_cast<float>(nValue);
Unary plus Unary minus Pre-increment Pre-decrement Logical NOT Bitwise NOT C-style cast Size in bytes Address of Dereference Dynamic memory allocation Dynamic array allocation Dynamic memory deletion Dynamic array deletion
nValue = +5;M nValue = -1; ++nValue; nValue; if (!bValue) nFlags = ~nFlags; float fValue = (float)nValue; sizeof(int); address = &nValue; nValue = *pnValue; int *pnValue = new int; int *panValue = new int[5]; delete pnValue; delete[] panValue;
4 L->R
->* .*
* 5 L->R / %
6 L->R
+ -
Addition Subtraction
7 L->R
<< >>
Comparison less than Comparison less than or equals Comparison greater than Comparison greater than or equals
9 L->R
== !=
Equality Inequality
if (x == y) if (x != y)
10 L->R
&
Bitwise AND
11 L->R
Bitwise XOR
12 L->R
Bitwise OR
13 L->R
&&
Logical AND
14 L->R
||
Logical OR
if (bValue1 || bValue2)
15 L->R
?:
Arithmetic if
Assignment Multiplication assignment Division assignment Modulus assignment Addition assignment Subtraction assignment Bitwise shift left assignment Bitwise shift right assignment Logical AND assingment Logical OR assignment Logical XOR assignment
nValue = 5; nValue *= 5; fValue /= 5.0; nValue %= 5; nValue += 5; nValue -= 5; nFlags <<= 2; nFlags >>= 2; nFlags &= 17; nFlags |= 17; nFlags ^= 17;
17 L->R
Comma operator
Preprocessors directives:
#ifndef <NOMBRE> (asking if NOMBRE is defined) #endif (close the block if)