Name | Symbol Usage | Precedence | Associativity | Arity |
Global Scope Resolution | ::giInt | 17 | Right | Unary |
Class Scope Resolution | CMyClass::tiInt | 17 | Left | Binary |
Namespace Scope Resolution | NMyNamespace::tiInt | 17 | Left | Binary |
Dot | qMyObj.miInt | 16 | Left | Binary |
Arrow | qpMyObjPtr->miInt | 16 | Left | Binary |
Subscript | iaIntArray[uiIndex] | 16 | Left | Binary |
Postfix Increment | iInt++ | 16 | Right | Unary |
Postfix Decrement | iInt-- | 16 | Right | Unary |
Sizeof | sizeof() | 16 | Right | Unary |
Prefix Increment | ++iInt | 15 | Right | Unary |
Prefix Decrement | --iInt | 15 | Right | Unary |
Bitwise Not | ~uiInt | 15 | Right | Unary |
Logical Not | !bBool | 15 | Right | Unary |
Negation | -iInt | 15 | Right | Unary |
Unary Plus | +iInt | 15 | Right | Unary |
Address Of | &iInt | 15 | Right | Unary |
Dereference | *ipIntPtr | 15 | Right | Unary |
New | new CMyClass | 15 | Right | Unary |
Delete | delete qpMyObj | 15 | Right | Unary |
Type Conversion/Cast | (double)iInt | 15 | Right | Unary |
Dot Dereference | qMyObj.*mipDataPtr | 14 | Left | Binary |
Arrow Dereference | qpMyObjPtr->*mipDataPtr | 14 | Left | Binary |
Multiplication | iInt1 * iInt2 | 13 | Left | Binary |
Division | iInt1 / iInt2 | 13 | Left | Binary |
Modulus | iInt1 % iInt2 | 13 | Left | Binary |
Addition | iInt1 + iInt2 | 12 | Left | Binary |
Subtraction | iInt1 - iInt2 | 12 | Left | Binary |
Shift Left | uiBits << uiShift | 11 | Left | Binary |
Shift Right | uiBits >> uiShift | 11 | Left | Binary |
Less Than | iInt1 < iInt2 | 10 | Left | Binary |
Less Than or Equal | iInt1 <= iInt2 | 10 | Left | Binary |
Greater Than | iInt1 > iInt2 | 10 | Left | Binary |
Greater Than or Equal | iInt1 >= iInt2 | 10 | Left | Binary |
Equal | iInt1 == iInt2 | 9 | Left | Binary |
Not Equal | iInt1 != iInt2 | 9 | Left | Binary |
Bitwise And | uiBits1 & uiBits2 | 8 | Left | Binary |
Bitwise Exclusive Or | uiBits1 ^ uiBits2 | 7 | Left | Binary |
Bitwise Or | uiBits1 | uiBits2 | 6 | Left | Binary |
Logical And | bBool1 && bBool2 | 5 | Left | Binary |
Logical Or | bBool1 || bBool2 | 4 | Left | Binary |
Conditional | bBool ? iIntTrue : iIntFalse | 3 | Left | Ternary |
Assignment | iIntDest = iIntSrc | 2 | Right | Binary |
Multiplication Assignment | iIntDest *= iIntSrc | 2 | Right | Binary |
Division Assignment | iIntDest /= iIntSrc | 2 | Right | Binary |
Modulus Assignment | iIntDest %= iIntSrc | 2 | Right | Binary |
Addition Assignment | iIntDest += iIntSrc | 2 | Right | Binary |
Subtraction Assignment | iIntDest -= iIntSrc | 2 | Right | Binary |
Shift Left Assignment | iIntDest <<= iIntSrc | 2 | Right | Binary |
Shift Right Assignment | iIntDest >>= iIntSrc | 2 | Right | Binary |
And Assignment | uiBitsDest &= uiBitsSrc | 2 | Right | Binary |
Or Assignment | uiBitsDest |= uiBitsSrc | 2 | Right | Binary |
Exclusive Or Assignment | uiBitsDest ^= uiBitsSrc | 2 | Right | Binary |
Comma | iIntArg1, iIntArg2 | 1 | Left | Binary |
Example 1
// Prefix increment: increment then output 1
int iX = 0;
cout << ++iX << endl;
Example 2
// Postfix increment: output 0 then increment
int iX = 0;
cout << iX++ << endl;
Example 3
// Prefix decrement: decrement then output -1
int iX = 0;
cout << --iX << endl;
Example 4
// Postfix decrement: output 0 then decrement
int iX = 0;
cout << iX-- << endl;
Example 1
// Addition
int iSum = 1 + 2;
Example 2
// Subtraction
int iDifference = 2 - 1;
Example 3
// Multiplication
int iProduct = 3 * 2;
Example 4
// Division
double dQuotient = 4.0 / 3.0;
Example 5
// Modulus
int iRemainder = 10 % 3;
Example 1
// And
bool bAnd = (bIsFirst && bIsFull);
Example 2
// Or
bool bOr = (bIsLast || bIsEmpty);
Example 3
// Not
bool bNot = !bDone;
Example 1
// Less than if (iX < iY) { // Some code }
Example 2
// Greater than if (iX > 10) { // Some code }
Example 3
// Equal to if (4 == iY) { // Some code }
Example 4
// Less than or equal to if (8.1 <= dZ) { // Some code }
Example 5
// Greater than or equal to if (dX >= dZ) { // Some code }
Example 6
// Not equal to if (dX != 10.5) { // Some code }
Example 1
// Use a mask and bitwise and to extract least two bits of uiX
unsigned int uiAnd = (uiX & 3);
Example 2
// Use the lowest byte mask and bitwise or to ignore the last byte
unsigned int uiMatchIP = (uiAddressIP | 255);
Example 3
// Use bitwise exclusive or to swap without a third variable unsigned int uiA = 46; unsigned int uiB = 73; // This swaps the values of uiA and uiB uiA = uiA ^ uiB; uiB = uiA ^ uiB; uiA = uiA ^ uiB;
Example 4
// Use the bitwise not to get the photo negative of a pixel
unsigned int uiNegative = ~uiPixelColor;
Example 1
// Use the right shift to divide by two
unsigned int uiHalfX = (uiX >> 1);
Example 2
// Use the left shift to multiply by eight
unsigned int uiEightX = (uiX << 3);
Example 1
// Simple assignment
uiX = uiY;
Example 2
// Add uiY to uiX
uiX += uiY;
Example 3
// Subtract uiY from uiX
uiX -= uiY;
Example 4
// Multiply uiX by uiY
uiX *= uiY;
Example 5
// Divide uiX by uiY
uiX /= uiY;
Example 6
// Take the modulus of uiX with respect to 2
uiX %= 2;
Example 7
// Divide uiX by 4
uiX >>= 2;
Example 8
// Multiply uiX by 16
uiX <<= 4;
Example 9
// Keep the last 8 bits of uiX
uiX &= 255;
Example 10
// Turn on the last 2 bits of uiX
uiX |= 3;
Example 11
// Alternate the last 4 bits of uiX
uiX ^= 15;
Example 1
// Simple if-then
unsigned int uiX = (uiZ > 5) ? 5 : 10;
Example 1
// Simple pointer assignment
double*dpX = &dX;
Example 1
// Assign dX the value of dY via the pointer dpX
double*dpX = &dX;
*dpX = dY;
Example 1
// The variable iX takes on values 0 to 19 and // iY takes on the corresponding powers of 2 int iX; int iY; for (iX = 0, iY = 1; iX < 20; ++iX, iY * = 2) { // Some code }
Example 2
// Pass multiple arguments to a function
MyFunction(iX, iY);
Example 1
// Assign iNegX the value of iX with the opposite sign
int iNegX = -iX;
Example 2
// The unary plus does not affect anything. This sets iX equal to iY
int iX = +iY;
Example 1
// Call a member function of an object with two double arguments
CMyClass qMyObj;
qMyObj.MyFunction(10.9, 8.3);
Example 1
// Set the value of a data member of an object
CMyClass* qpMyObj = new CMyClass;
QpMyObj->miX = iY;
Example 1
// Declare and initialize a member data pointer double CMyClass::*mdpDataPtr = &CMyClass::mdX; CMyClass qMyObj; // Assign qMyObj.mdX the value 10.0 via the member data pointer qMyObj.*mdpDataPtr = 10.0;
Example 2
// Declare and initialize a member function pointer void (CMyClass::mpfnFnPtr)(double) = &CMyClass::SetX; CMyClass qMyObj; // Call qMyObj.SetX(15.2) via the member function pointer qMyObj.*mpfnFnPtr(15.2);
Example 1
// Declare and initialize a member data pointer double CMyClass::*mdpDataPtr = &CMyClass::mdX; CMyClass* qpMyObj = &qSomeObject; // Assign qpMyObj->mdX the value 10.0 via the member data pointer qpMyObj->*mdpDataPtr = 10.0;
Example 2
// Declare and initialize a member function pointer void (CMyClass::mpfnFnPtr)(double) = &CMyClass::SetX; CMyClass* qpMyObj = &qSomeObject; // Call qpMyObj->SetX(15.2) via the member function pointer qpMyObj->*mpfnFnPtr(15.2);
Example 1
// Use the class scope resolution operator to access the class function
CMyClass::MyFunction(3.6);
Example 2
// Use the namespace scope resolution operator to assign variable a value
NMyNamespace::mdX = 3.6;
Example 3
// Use the global scope resolution operator to break out of local scope
::MyFunction(3.6);
Example 1
// Type Conversion from a double to an inttruncates to 14
double dX = 14.7;
int iX = (int)dX;
Example 2
// Type cast from an unsigned int to // an unsigned chartakes lowest byte = 252 or 0xFC unsigned int uiInt = 0xFFFEFDFC; unsigned int* uipIntPtr = &uiInt; unsigned char* ucpLowByte = (unsigned char*)uipIntPtr;
Example 1
// Access an element of an array to set a char to 'X'
char caName[] = "XoaX.net";
char cX = caName[3];
Example 1
// Get the size in bytes of a data instance
int iInt = 10;
unsigned int uiIntSize = sizeof(iInt);
Example 2
// Get the size in bytes of a data type
unsigned int uiDblSize = sizeof(double);
Example 3
// Get the number of elements in an array // Then divide the array size by the element size double daArray[] = {3.4, 8.1, 7.4}; unsigned int uiArraySize = sizeof(daArray) / sizeof(daArray[0]);
Example 1
// Dynamically allocate and deallocate a single variable int* ipX = new int; // Some code delete ipX;
Example 2
// Dynamically allocate and deallocate an array double* dpVector = new int[10]; // Some code delete []dpVector;
Example 3
// Allocate an array of function pointers, // which take no arguments and return an int int *fnpaFnPtrArray = new (int (*[5])()); // Some code // Deallocate the array delete [] fnpaFnPtrArray;
© 20072025 XoaX.net LLC. All rights reserved.