I can't be sure if I am right, but here is a possible explanation:
Every function in c and as well as in c++ is a potential variable.
Possible declaration of function is:
int (*MyFunction)(int, double);
In this case- Variable name: MyFunction
| Type: function that returns int
with int, double
parameters.
So, even when you declare function, you actually declare variable with a "function" type. In this case, it is make sense why can you use, in your case (*add)(3, 2)
for function calling (or using a variable).
It may by more clearly for you to have a look on lambda expressions, which can make a function implementation, and then let you use it like a local function variable:
int(*MyFunction)(int, double) = [](int a, double b) -> int {
return (int)((a + b) * 10);
};
Here we declare on function type variable, and implement a function for it with a lambda expression. Now we can use it in two forms:
MyFunction(1, 2.5); // Like a regular function
(*MyFunction)(1, 2.5); // As a function type variable
Again, it is the most sense explanation that I could think of. I don't sure if it is a right/best/fully explanation, but I hope it gave you a new perspective of functions.