Skip to content

Instantly share code, notes, and snippets.

@cacharle
Created February 22, 2025 13:03
Show Gist options
  • Save cacharle/bf9b03e3067dd04e7e61f9dc2d774f08 to your computer and use it in GitHub Desktop.
Save cacharle/bf9b03e3067dd04e7e61f9dc2d774f08 to your computer and use it in GitHub Desktop.
function_ptr_return_function_ptr
#include <stdio.h>
int a(int x,int y){
return 1;
}
double b(int x, int y){
return 1.5;
}
void *function_factory(char arg) {
if (arg=='a') return &a;
if (arg=='b') return &b;
}
int main() {
int (*a2)(int, int) = function_factory('a');
double (*b2)(int, int) = function_factory('a');
printf("a(1, 2) = %d\n", a2(1, 2));
printf("b(1, 2) = %d\n", b2(1, 2));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment