#include <stdio.h>
#include <stdlib.h>
typedef struct t_ooxx
{
char *ip;
int w;
int h;
}T_ooxx, *PT_ooxx;
//测试数组指针
void test_ooxx_arrayP(T_ooxx (*p)[], int num)
{
printf("%s--%d--%d\n", (*p)[0].ip, (*p)[0].w, (*p)[0].h);
}
//测试指针数组
void test_ooxx_Parray(T_ooxx **p, int num)
{
printf("%s--%d--%d\n", p[0]->ip, p[0]->w, p[0]->h);
}
//测试函数指针
char *test_ooxxFP(void)
{
char *ooxx = "fuck";
printf("ooxx is what?\n");
return ooxx;
}
//测试指针函数变量
double (*test_ooxxPF)(T_ooxx *p, int num); //定义一个指针函数变量
typedef double (*test_ooxxPF_type)(T_ooxx *p, int num); //声明指针函数类型
/* 定义一个与指针函数相同形式的测试函数(一般为处理函数) */
double fuck_fHANDLE(T_ooxx *p, int num)
{
printf("this is a fuck function:%s-%d-%d\n", p->ip, p->w, p->h);
return 0;
}
//测试指针函数作为参数
//void * test_ooxx(double (*p)(T_ooxx *ooxx, int num) , int num)
void * test_ooxx_pm(test_ooxxPF_type p, int num) //也可以这样使用 声明的指针函数类型
{
T_ooxx ooxx = {"192.168.0.0",456,678};
p(&ooxx, 9); //草做,执行函数
printf("testing parameter is PF.\n");
}
int main()
{
//int a[10] = {1,2,3,4,5,6,7,8,9,10};
char *ip = "192.168.1.1";
/* 1 数组指针 */
T_ooxx (*ooxx)[9] = NULL;
/* if use malloc, sample...*/
ooxx = (T_ooxx (*)[])malloc( 1 * sizeof(T_ooxx)); //指针使用前,要确保指向合法地址
free(ooxx);
/* 一维数组,与二维数组的测试 */
#if 1
T_ooxx testAP[][9] = {
{
"192.168.1.110",123,321,
"192.168.1.119",222,333 //分组初始化
//.....还有7个
}
};
ooxx = testAP; //即&testAP[0]
#else
T_ooxx testAP[9]; //testAP[3], error 要指向的数组包含9个元素
testAP[0].ip = ip;
testAP[0].w = 12;
testAP[0].h = 34;
ooxx = &testAP; //取数组的地址
#endif
test_ooxx_arrayP(ooxx, sizeof(ooxx) / sizeof(ooxx[0]));
/* 2 指针数组 */
T_ooxx *ooxx2[9] = {0};
T_ooxx testPA = {
"192.168.1.199",
59,
69
};
ooxx2[0] = &testPA; //数组里面存放指针的地址
test_ooxx_Parray(ooxx2, 9);
/* 3 函数指针 */
char *t;
t = test_ooxxFP();
printf("the answer is %s\n", t);
/*4 指针函数*/
/*4.1 给指针函数变量赋值 */
test_ooxxPF = fuck_fHANDLE; // or test_ooxxPF = &fuck_fHANDLE;
/*4.2 指针函数变量作为参数*/
test_ooxx_pm(fuck_fHANDLE, 9); // test_ooxx(test_ooxxPF, 9);
return 0;
}
#include <stdlib.h>
typedef struct t_ooxx
{
char *ip;
int w;
int h;
}T_ooxx, *PT_ooxx;
//测试数组指针
void test_ooxx_arrayP(T_ooxx (*p)[], int num)
{
printf("%s--%d--%d\n", (*p)[0].ip, (*p)[0].w, (*p)[0].h);
}
//测试指针数组
void test_ooxx_Parray(T_ooxx **p, int num)
{
printf("%s--%d--%d\n", p[0]->ip, p[0]->w, p[0]->h);
}
//测试函数指针
char *test_ooxxFP(void)
{
char *ooxx = "fuck";
printf("ooxx is what?\n");
return ooxx;
}
//测试指针函数变量
double (*test_ooxxPF)(T_ooxx *p, int num); //定义一个指针函数变量
typedef double (*test_ooxxPF_type)(T_ooxx *p, int num); //声明指针函数类型
/* 定义一个与指针函数相同形式的测试函数(一般为处理函数) */
double fuck_fHANDLE(T_ooxx *p, int num)
{
printf("this is a fuck function:%s-%d-%d\n", p->ip, p->w, p->h);
return 0;
}
//测试指针函数作为参数
//void * test_ooxx(double (*p)(T_ooxx *ooxx, int num) , int num)
void * test_ooxx_pm(test_ooxxPF_type p, int num) //也可以这样使用 声明的指针函数类型
{
T_ooxx ooxx = {"192.168.0.0",456,678};
p(&ooxx, 9); //草做,执行函数
printf("testing parameter is PF.\n");
}
int main()
{
//int a[10] = {1,2,3,4,5,6,7,8,9,10};
char *ip = "192.168.1.1";
/* 1 数组指针 */
T_ooxx (*ooxx)[9] = NULL;
/* if use malloc, sample...*/
ooxx = (T_ooxx (*)[])malloc( 1 * sizeof(T_ooxx)); //指针使用前,要确保指向合法地址
free(ooxx);
/* 一维数组,与二维数组的测试 */
#if 1
T_ooxx testAP[][9] = {
{
"192.168.1.110",123,321,
"192.168.1.119",222,333 //分组初始化
//.....还有7个
}
};
ooxx = testAP; //即&testAP[0]
#else
T_ooxx testAP[9]; //testAP[3], error 要指向的数组包含9个元素
testAP[0].ip = ip;
testAP[0].w = 12;
testAP[0].h = 34;
ooxx = &testAP; //取数组的地址
#endif
test_ooxx_arrayP(ooxx, sizeof(ooxx) / sizeof(ooxx[0]));
/* 2 指针数组 */
T_ooxx *ooxx2[9] = {0};
T_ooxx testPA = {
"192.168.1.199",
59,
69
};
ooxx2[0] = &testPA; //数组里面存放指针的地址
test_ooxx_Parray(ooxx2, 9);
/* 3 函数指针 */
char *t;
t = test_ooxxFP();
printf("the answer is %s\n", t);
/*4 指针函数*/
/*4.1 给指针函数变量赋值 */
test_ooxxPF = fuck_fHANDLE; // or test_ooxxPF = &fuck_fHANDLE;
/*4.2 指针函数变量作为参数*/
test_ooxx_pm(fuck_fHANDLE, 9); // test_ooxx(test_ooxxPF, 9);
return 0;
}