C/C++ language has a feature which allows function pointer to be declared as a pointer variable.
Syntax of a function pointer is as follows:

<return type> (*<pointer name>)(<arguments>); or
 
typedef <return type> (*<pointer name>)(<arguments>);
Here is an example of addition using function pointer.
int add(int a, int b)
{
  return (a + b);
}
typedef int (add_proc)(int a, int b);
int main(int argc, char *argv[])
{
  add_proc add_ptr;
  int a = 1, b = 2, c;
  add_ptr = add;
  c = add_ptr(a, b);
}

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

parameter passing call-by-reference, structure as function argument, array as function argument, inline-functions, macro vs inline-function, function pointer, default C++ argument value, Recursion, factorial using recursion,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan