Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created March 12, 2014 19:07
Show Gist options
  • Save keizo042/9514025 to your computer and use it in GitHub Desktop.
Save keizo042/9514025 to your computer and use it in GitHub Desktop.
関数ポインタの練習。Cはメモリを直接弄れて全能感がある。
#include<stdio.h>
typedef int (*func)(int x, int y);
int cat(int, int);
int dog(int, int);
int bird(int, int);
int
main()
{
func functions[] ={
cat,
dog,
bird,
};
int i;
for(i=0;i <3;i++){
(*functions[i])(i*1,i*2);
}
}
int cat(int x, int y)
{
printf("there are %d cats and %d times nyaa\n",x,y);
}
int dog(int x, int y)
{
printf("there are %d dogs and %d times bow\n",x,y);
}
int bird(int x, int y)
{
printf("there are %d bird and %d times fly away\n",x,y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment