C语言赋值函数指针
示例
#include <stdio.h>
/* increment: take number, increment it by one, and return it */
int increment(int i)
{
printf("increment %d by 1\n", i);
return i + 1;
}
/* decrement: take number, decrement it by one, and return it */
int decrement(int i)
{
printf("decrement %d by 1\n", i);
return i - 1;
}
int main(void)
{
int num = 0; /* declare number to increment */
int (*fp)(int); /* declare a function pointer */
fp = &increment; /* set function pointer to increment function */
num = (*fp)(num); /* increment num */
num = (*fp)(num); /* increment num a second time */
fp = &decrement; /* set function pointer to decrement function */
num = (*fp)(num); /* decrement num */
printf("num is now: %d\n", num);
return 0;
}
热门推荐
10 新年喝酒祝福语大全简短
11 立春祝福语简短微信
12 送朋友内裤祝福语简短
13 宝宝生日奶奶祝福语简短
14 哥哥新婚搞笑祝福语简短
15 二零二一年祝福语简短
16 作品棒棒哒祝福语简短
17 英语寄信祝福语范文简短
18 晚安幽默祝福语简短