Search⌘ K

Calling Functions

Explore how to call functions in C using their memory addresses with function pointers. Understand how to store function addresses and invoke them using pointers, including the correct syntax for defining and calling function pointers. This lesson helps you grasp an advanced method of function invocation that is useful for dynamic and flexible programming.

We'll cover the following...

Let’s see how we can call a function using its address in memory.

Example program

C
# include <stdio.h>
void display( ) ;
int main( )
{
void (*p)( ) ;
// One way
display() ;
p = display ;
// Two more ways
( *p )( ) ;
p( ) ;
}
void display( )
{
printf ( "Hello\n" ) ;
}

Explanation

Normally a function is called using its name, such as the call, display( ), in the code above.

We ...