C
This commit is contained in:
36
learnc/learnc15.c
Executable file
36
learnc/learnc15.c
Executable file
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void f1(int var)
|
||||
{
|
||||
printf("this is f1 and var is: %d\n", var);
|
||||
}
|
||||
|
||||
void f2(int var)
|
||||
{
|
||||
printf("this is f2 and var is: %d\n", var);
|
||||
}
|
||||
|
||||
void f3(int var)
|
||||
{
|
||||
printf("this is f3 and var is: %d\n", var);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
/* define an array full of function pointers
|
||||
to the above functions, that take an `int` as
|
||||
their only argument */
|
||||
void(*fp[])(int) = {f1, f2, f3};
|
||||
|
||||
int c = 0;
|
||||
while(c < 3)
|
||||
{
|
||||
/* call the functions using the function pointers
|
||||
of the array at index `c` with `c` as an argument */
|
||||
fp[c](c);
|
||||
|
||||
++c;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user