Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiopon01/502bd54e4d994de485ff09be85752f75 to your computer and use it in GitHub Desktop.
Save shiopon01/502bd54e4d994de485ff09be85752f75 to your computer and use it in GitHub Desktop.
// 関数ポインタ
#include <stdio.h>
int kansu(int a)
{
return a * 2;
}
void main()
{
int (*p)(int x) = kansu;
printf("%p\n", kansu); // => 0x4011a0
printf("%p\n", p); // => 0x4011a0
printf("%d\n", p(10)); // => 20
}
// コールバック関数
#include <stdio.h>
int callback_kansu(int n)
{
return n * 2;
}
void func(int num, int (*cb)(int)){
printf("num * 2 = %d\n", cb(num));
}
void main()
{
func(1024, callback_kansu); // => "num * 2 = 2048"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment