Class 20: Function Pointers Flashcards
Int (*func1)()
Function pointer
Are the parentheses around (*func) necessary?
Yes or else the compiler will treat this as a declaration of a function which RETURNS a pointer and not a function pointer
Suppose you have the following function pointer
Int (fp)(int, int)
And the function
Int return max(int size, const int*array)
Fp = &returnMax
Or fp = returnMax
ReturnMax must be declared (but not necessarily defined) before assigning to address to the function
If function has not parameters and not return value, how would be call the function suing function pointer
(*fp)()
Can you call using a function pointer without dereferencing?
Yes
Ex:
Int I = fp(argument1, argument2)
I = fp()
Array of function pointers
Float (*fp_array[4])(float,float);
Fp_array[0]= add;
Fp_array[1] = substract;
Fp_array[2] = multiply;
Fp_array[3] = divide;
Passing a pointer to the array of function pointers is passed to the function
Float math_op(**fp_array)(float,float))