函数指针

#include <stdio.h>
int testfunc(void)
{
    printf("just test
");
    return 5;
}

int main()
{
    int (*ptr)(void);
    ptr = testfunc;
    int c = (*ptr)();
    printf("%d
",c);
    return 0;
}

1.函数testfunc与普通函数定义相同

2.函数指针*ptr,类型与函数类型相同,后面括号中与函数参数类型相同

3.为函数指针ptr赋值为testfunc,则使用*ptr相当于testfunc,所以后面必须加()

原文地址:https://www.cnblogs.com/punkrocker/p/4631808.html