函数指针赋值方法

作者在 2008-10-07 23:33:37 发布以下内容
// 2008/10/7  VC6.0

#include<stdlib.h>
#include<stdio.h>

typedef int (*pFunc)(float a);

int test(float a)
{
     printf("test %f",a);
     return 0;
}

int main()
{
    pFunc pFunc1 = test;  // 函数指针赋值
    pFunc1(4.5);
    printf("\nhello");
    getchar();
    return 0;
}

技术 | 阅读 9207 次
文章评论,共2条
duanchangren
2008-10-08 01:40
1
能不能再讲细点
vfdff(作者)
2008-10-08 23:48
2
代参数函数指针的赋值方法<br />
#include&lt;stdio.h&gt;<br />
<br />
typedef void (*pFunc)(float a);<br />
<br />
int atexitf( void (*func)(float),float a)<br />
//int atexitf( pFunc func,float a)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;func(a);<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
}<br />
<br />
void test(float a)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;test %f\n&quot;,a);<br />
}<br />
<br />
int main()<br />
{<br />
&nbsp;&nbsp;&nbsp; pFunc pFunc1 = (pFunc)test;&nbsp;&nbsp;// 函数指针赋值<br />
&nbsp;&nbsp;&nbsp; pFunc1(4.5);<br />
&nbsp;&nbsp;&nbsp;&nbsp;atexitf(pFunc1,(float)3.66);<br />
&nbsp;&nbsp;&nbsp;&nbsp;atexitf(test,(float)3.76);<br />
&nbsp;&nbsp;&nbsp; printf(&quot;hello\n&quot;);<br />
&nbsp;&nbsp;&nbsp; return 0;<br />
}<br />
注意:<br />
int atexitf( void (*func)(float a))<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;func(a);<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
}非法
游客请输入验证码
浏览1944050次