Created
April 20, 2017 08:13
-
-
Save shiopon01/502bd54e4d994de485ff09be85752f75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 関数ポインタ | |
#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