An excerpt from Object-Oriented Programming with C++ by E Balagurusamy-
Using function pointers, we can allow a C++ program to select a function dynamically at run time. We can also pass a function as an argument to another function. Here, the function is passed as a pointer. The function pointer cannot be de-referenced. C++ also allows us to compare two function pointers.
Here it is written that function pointers cannot be dereferenced. But the following program ran successfully.
#include<iostream>
int Multiply(int i, int j) {
return i*j;
}
int main() {
int (*p)(int , int);
p = &Multiply;
int c = p(4,5);
int d = (*p)(4,11);
std::cout<<c<<" "<<d;
return 0;
}
Here on the 4th last line, I have de-referenced the pointer. Is it correct? It was not giving any compiler time error, also what is written in the 4th last line is the same as what is written in the 5th last line? I have started learning C++ so please don't mind if I have asked something really stupid.