関数ポインタを使う 関数ポインタはポインタの一種で文字通り関数のポインタの事で、関数を遠隔操作できるようになる文法です。たぶんほとんどの場合関数の引数として使うんじゃないかと思うのでそれだけ紹介します。 #include<stdio.h> int add(int a,int b){ return a+b; } int sub(int a,int b){ return a-b; } //関数ポインタを使っている int calc(int (*func)(int,int),int a,int b){ return func(a,b); } int main(void){ int x = 10; int y = -4; int ans1 = calc(add,x,y); //足し算をしている int ans2 = calc(sub,x,y); //引き算をしている printf("%d,%d\n
