#include <stdio.h>
int add(int, int);
int sub(int, int);
int mul(int, int);
int div(int, int);
int add(int var1, int var2)
{
return var1 + var2;
}
int sub(int var1, int var2)
{
return var1 - var2;
}
int mul(int var1, int var2)
{
return var1 * var2;
}
int div(int var1, int var2)
{
return var1 / var2;
}
int main(int argc, char **argv)
{
int (*fun_table[4]) ();
int result = 0;
fun_table[0] = add;
fun_table[1] = sub;
fun_table[2] = mul;
fun_table[3] = div;
result = (*fun_table[0])(100, 5);
printf("add : %d\n", result);
result = (*fun_table[1])(100, 5);
printf("sub : %d\n", result);
result = (*fun_table[2])(100, 5);
printf("mul : %d\n", result);
result = (*fun_table[3])(100, 5);
printf("div : %d\n", result);
return 0;
}
A Blog to learn Software Technologies like C, Golang and Java
Function table in C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment