Class 20: Function Pointers Flashcards

1
Q

Int (*func1)()

A

Function pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Are the parentheses around (*func) necessary?

A

Yes or else the compiler will treat this as a declaration of a function which RETURNS a pointer and not a function pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Suppose you have the following function pointer
Int (fp)(int, int)

And the function
Int return max(int size, const int*array)

A

Fp = &returnMax
Or fp = returnMax

ReturnMax must be declared (but not necessarily defined) before assigning to address to the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If function has not parameters and not return value, how would be call the function suing function pointer

A

(*fp)()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can you call using a function pointer without dereferencing?

A

Yes
Ex:
Int I = fp(argument1, argument2)
I = fp()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Array of function pointers

A

Float (*fp_array[4])(float,float);
Fp_array[0]= add;
Fp_array[1] = substract;
Fp_array[2] = multiply;
Fp_array[3] = divide;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Passing a pointer to the array of function pointers is passed to the function

A

Float math_op(**fp_array)(float,float))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly