0% found this document useful (0 votes)
2 views

C++ Techinques cheat sheet

Uploaded by

Mohamed Mounir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C++ Techinques cheat sheet

Uploaded by

Mohamed Mounir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//Basics: //Pointers:

/*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 */); //======================//
//======================//

//Classes: //Dynamic Allocation:


/*Definition*/ int* ptr = new int;
class ClassName //dynamically allocating an int
{ int* ptr = new int(value);
private: //dynamically allocating an int initialized
/* data */ with "value"
public: delete ptr;
ClassName(/* args */); //dynamically unallocating an int
~ClassName(); int* ptr = new int[SIZE];
}; //dynamically allocating an array of int
delete[] ptr;
/*Methods Definition*/ //dynamically deleting an array of int
ClassName::ClassName(/* args */)
:_DataMember1(Input1),
//initializer list //Array as Function Argument:
_DataMember2(Input2), void Function(int arr[]) {}
object1(ConstructorArguments1) //unsized array
{ void Function(int arr[SIZE]) {} //sized
} array
void Function(int* arr) {}
ClassName::~ClassName() //pointer
{
}
//======================//

You might also like