Created
February 22, 2025 13:03
-
-
Save cacharle/bf9b03e3067dd04e7e61f9dc2d774f08 to your computer and use it in GitHub Desktop.
function_ptr_return_function_ptr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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