Advertisement
kyoo0000

function array

Oct 4th, 2020
1,359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<stdbool.h>
  5.  
  6. char* f1(int a) {
  7.     char* str = (char*) calloc(15, sizeof(char));
  8.     sprintf(str, "%d", a);
  9.     return str;
  10. }
  11.  
  12. char* f2(int a, int b) {
  13.     char* str = (char*) calloc(15, sizeof(char));
  14.     sprintf(str, "%d", a + b);
  15.     return str;
  16. }
  17.  
  18. char* (*fun_p[])() = {&f1, &f2};
  19.  
  20. int main(void) {
  21.     int a = 1, b = 6;
  22.     char* f1 = fun_p[0](a);
  23.     char* f2 = fun_p[1](a, b);
  24.  
  25.     printf("%s\n%s\n", f1, f2);
  26.  
  27.     free(f1); free(f2);
  28.    
  29.     return EXIT_SUCCESS;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement