C++ Pointers cookbook Cheat Sheet
by Nima (nimakarimian) via cheatography.com/113429/cs/21694/
Array of Pointers Pointer vs array Pointer to pointer
int *ptr[arraysize] = array of pointers, int b[10]; int A pointer to a pointer is a
pointing to int *bptr; form of multiple indirection or
bptr=b; OR a chain of pointers
Pointer to function bptr=&b[0]; int var;
int (*FuncPTR)(int a,int b); *(bptr+3) // shows int *ptr;
//called funcptr is a pointer the value of b[3] int **pptr;
to function bptr+3 // points var = 3000;
// actually is used as a to &b[3] ptr = &var; // take the
parameter of another func and //an array can be address of var
can pass any func to the desired used like a pointer pptr = &ptr;// take the
func as a parameter with this too -> *(b+3)‐ address of ptr using address of
method =value of b[3] operator &
int func1(int); //pointer to an
int func2(int); array can be used Return pointer from functions
int func3(int (*FuncPTR)(int)); like an array -> int * getRandom( ) {
now we can pass func1 or func2 bptr[3] = value of static int r[10];
to func3 ; b[3] return r;
}
Array of Pointers to functions NULL pointer // main function to call above
void (*f[3])(int)= int *ptr = NULL; defined function.
{function1,function2,function3}; //The value of ptr int main () {
// f is an array of pointers , is 0 int *p;
pointing to functions of type if(ptr) // succeeds p = getRandom();
void which all of them take one if p is not null }
parameter of type int . if(!ptr) //
succeeds if p is Array of strings
null char *color=
{"red","blue","yellow','green"};
passing pointers to //color is an array of pointers
functions
, pointing to the first
WHEN PASSING character of each string
ARGUMENTS
unsigned long
sec;
getSeconds(
&sec );
IN FUNCTION HEADER
void getSeconds(u‐
nsigned long *par)
By Nima (nimakarimian) Published 29th January, 2020. Sponsored by Readable.com
Last updated 29th January, 2020. Measure your website readability!
Page 1 of 1. https://readable.com
cheatography.com/nimakarimian/