How to pass a pointer to function to another function as parameter in C

1 Answer

0 votes
#include <stdio.h>
 
int (*functionPointer)(int, int);
int sum_function(int a, int b);
int sum_function_pointer(int (*functionPtr)(int, int));

int main(void)
{
    functionPointer = sum_function;
    
    int s = sum_function_pointer(functionPointer);
    printf("%d", s);
    
    return 0;
}

int sum_function(int a, int b) 
{
    return a + b;
}

int sum_function_pointer(int (*functionPtr)(int, int)) 
{
    return (*functionPtr)(7, 3);
}

/*
run:
 
10

*/

 



answered Nov 25, 2015 by avibootz

Related questions

...