Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
C: return function pointer
#include <assert.h>
int sum(int a, int b)
return a + b;
int multi(int a, int b)
return a * b;
int (*get_func_ptr(void))(int, int)
return &sum;
int main(int argc, char *argv[])
int (*func_ptr)(int, int);
func_ptr = &multi;
assert(func_ptr(2, 3) == 6);
assert(get_func_ptr()(2, 3) == 5);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment