How to use pointer to function with parameters in C

2 Answers

0 votes
#include <stdio.h>
 
void f(int n) {
    printf("%i\n", n);
}
 
   
int main() 
{ 
  void (*fp)(int) = f;
   
  fp(234);
   
  return 0; 
}
 
 
 
/*
run:
 
234
 
*/

 



answered Apr 6, 2019 by avibootz
edited Jul 26, 2019 by avibootz
0 votes
#include <stdio.h>

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

  
int main() 
{ 
  int (*fp)(int, int) = f;
  
  printf("%i", fp(4, 9));
  
  return 0; 
}



/*
run:

13

*/

 



answered Apr 6, 2019 by avibootz

Related questions

1 answer 161 views
1 answer 160 views
1 answer 150 views
2 answers 152 views
1 answer 159 views
159 views asked May 16, 2022 by avibootz
1 answer 260 views
...