C++ Techinques cheat sheet
C++ Techinques cheat sheet
/*Selectors*/ /*Declarations*/
if (/* condition */) int* ptr; //pointer to int
{ const int* ptr; //pointer to
/* code */ constant int
} int* const ptr; //constant
else if (/* condition */) pointer
{ const int* const ptr; //constant
/* code */ pointer to constant int
} int const* ptr; //also pointer
else to constant int
{ int const* const ptr; //also constant
/* code */ pointer to constant int
} int* ptr[SIZE]; //array of
pointers to int
switch (expression)
{ /*Dereferencing*/
case /* constant-expression */: *ptr = 100; //making the value of what
/* code */ "ptr" is pointing to 100
break; //======================//
default:
break; //Referencing:
} /*Declaring*/
int Var; //Declaring an int
/*Loops*/ variable
for (size_t i = 0; i < count; i++) int& Ref = Var; //Declaring a referance
{ to "Var"
/* code */
} /*As Function Argument*/
void Function(int& Var) //in function
while (/* condition */) definition
{ {
/* code */ /*code*/
} }
int Var = 10; //defining an int
do variable
{ Function(Var); //passing to funtion
/* code */ (no & is added)
} while (/* condition */); //======================//
//======================//