What is the function pointer

  1. The function pointer is a type of pointer, when dereferenced, which invokes a function, passing it zero or more arguments just like a normal function.
  2. The function pointer make it possible that a function is selected to execute based on the run-time values. This can also be achieved by the virtual function in C++.
  3. The function pointer also makes it possible that a function caller could control the behavior of the function by passing it a function pointer. This is much better than passing it a flag.
  4. Java doesn't support the function pointer.
  5. The function pointer is less error prone than the normal pointers because you will never allocate or deallocate memory with them.
  6. C++ virtual functions are implemented with virtual table pointed by a vitual pointer. Actual the virtual pointer is the function pointer.
  7. A function pointer always points to a function with a specific signature. Thus all functions, you want ot use with the same function pointer, must have the same parameters and return-type.

Reference:

Function Pointer Tutorials: http://www.newty.de/fpt/index.html

No comments:

Post a Comment