codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C function pointers

C function pointers

Store a function in a variable.

Declare as int (*f)(int,int). Used for callbacks and menus.

Example code

#include <stdio.h>
int add(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main() {
  int (*f)(int, int) = mul;
  printf("%d %d\n", add(2, 3), f(2, 3));
  return 0;
}

Run this code in the online editor

← C recursionC create and write files →