【这是一个C语言指针、结构体、函数指针、指针函数等操作】
根目录文件使用
#include""
而不是
#include<>
类型标识符 *函数名(参数表)
int *f(x,y);
说明:一般返回的是指针(地址)
使用方法:指针函数赋值给指针(*p=*f(x,y))
调用:访问指针 *P完成调用
#include<iostream>
#include<stdio.h>
char *point_funcation(char *p,char n);//使用函数指针调用任意数值值
char data[]={0x00,0x01,0x03,0x04,0x05};
int main()
{
int a,b;
char *pa;
a=10,
b=a+10;
// printf("%d",b);
*pa=*point_funcation(data,3);
printf("%d\n",*pa);
std::cout <<"hello"<< std::endl;
//system("pause");
}
char *point_funcation(char *p,char n)
{
char *pnt;
pnt=(p+n);
return (pnt);
}
返回值类型 ( * 指针变量名) ([形参列表]);
int (*f)(x,y);
说明:可以直接将函数赋值给指针
调用方法:先将函数赋值给函数指针 再调用 f(x,y);
#include<iostream>
#include<stdio.h>
void (*functon_point)(void );
void change(void(*pn)(void) );
void dsply_data(void);
void drect_funcation();
char data[]={0x00,0x01,0x03,0x04,0x05};
int main()
{
int a,b;
char *pa;
a=10,
b=a+10;
change(dsply_data); //将函数传递给函数指针
functon_point(); //调用函数指针
functon_point=drect_funcation; //函数指针赋值到入口参数
functon_point(); //调用函数指针
std::cout <<"hello"<< std::endl;
//system("pause");
}
void change(void(*pn)(void) )//入口函数类型一致和函数指针一致
{
functon_point=pn;
}
void dsply_data(void)
{
printf("this is funcation point\r");
}
void drect_funcation()
{
printf("data drect to funcaton\r");
}
int *p ,a;
p=&a;
(*p)++;
++*p;
*p++;
其中p 是指针变量 ,p=&a 代表P指向a的地址,*p是a的值。
(*p)++ 等同于 ++p 运算后同样指向a, 但是p++ 指的是将p的值加1 ,运算后p的值不指向a了。
float function1(float f);//定义积分函数
short N;//设计多次积分N
float h;//定义h=(a-b)/N 积分的小区间
s=(function1(a)+function1(b))/2; //计算中间值的积分 第一个值
for (i=i;i<N;i++)
{
s+=function1(a+i*h);//计算单个积分长度总和
}
return s*h;//计算出长度*H 等于面积 即积分