C语言 typedef函数指针用法和注意点

1 . fun1表示函数返回值为空和形参为空的类型名(fun1如同声明变量的int)
#include<stdio.h>
typedef void fun1(void);   
void test1(void)
{
        printf("fun1\n");
}
int main()
{
        fun1 *echo; //声明一个存储返回值为空和形参为空的函数指针变量
        echo=test1;
        echo();
        return 0;
}
2 . fun2表示函数返回值为空和形参为空的类型名(fun2如同声明指针变量的int *)
#include <stdio.h>
typedef void (*fun2)(void);
void test()
{
        printf("fun2\n");
}
int main()
{
        fun2 echo;  
        echo=test;
        echo();
        return 0;
}
3 . fun3表示函数返回值为空指针和形参为空的类型名 ( fun1如同声明变量的int )
#include <stdio.h>
typedef void* fun3(void);  
void* test(void)   //返回空类型指针
{
        printf("fun3\n");
        return NULL;
}
int main()
{
        fun3 *echo;
        echo=test;
        echo();
        return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值