I have asked a question here on SO about the use of function pointer and someone has replied giving the example of classic calculator
float Plus (float a, float b) { return a+b; }
float Minus (float a, float b) { return a-b; }
float Multiply(float a, float b) { return a*b; }
float Divide (float a, float b) { return a/b; }
in some way you select your operation
/* Here there should be an if or a switch/case that selects the right operation */
float (*ptrFunc)(float, float) = Plus;
Now here he says "here there should be an if or a switch/case that selects the right operation"
And have read many times function pointer can be used to replace if or switch/case statement but not able to understand (even in this calculator example) how function pointer can replace if or switch/case?
Can anyone help me how do I visualize function pointer replacing if or switch/case.