您的位置:首页 > 其它

为结构体中函数指针赋值的两种方法

2013-08-16 12:00 176 查看
/**
* 为结构体中的指针数组赋值
*/

#include <stdio.h>

typedef struct test
{
void (*p)(void);
void (*q)(void);
void (*y)(void);
}test;

void f1(void)
{
printf("f1\n");
}

void f2(void)
{
printf("f2\n");
}

void f3(void)
{
printf("f3\n");
}

int main(void)
{
test aa = {
p : f1, //方法1
.q = f2, //方法2, 一般这种方式在全局变量初始化的时候常用
};
aa.y = f3; //方法3

aa.p();
aa.q();
aa.y();

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: