関数へのポインタ
関数へのポインタも宣言できる。
関数へのポインタは、メモリ内にある関数の先頭アドレスを値としてもつ。
例
#include <stdio.h> void function1(void); int main (void) { void (*f)(void); //関数へのポインタを宣言 f = function1; //ポインタへ関数の先頭アドレスを代入 printf("%p\n", function1); printf("%p\n", f); function1(); (*f)(); //関数ポインタを実行 return 0; } void function1(void) { printf("function1\n"); }
実行結果
0x8048441 0x8048441 function1 function1