数组指针与函数指针

时间:2021-03-04 18:57:20
#include "stdafx.h"

void te_array_ptr(void)
{
//correct
//char a[10] = "123456";
//char (*p)[10];
//p = &a;
//printf("%c\r\n",(*p)[1]);


//correct
char a[10] = "123456";
char (*p)[10] = &a;
printf("%c\r\n",(*p)[1]);


//char *a = "123456";
//char (*p)[10] = (char(*)[10])a;
//printf("%c\r\n",(*p)[1]);


//char *a = "123456";
//char (*p)[10];
//p = (char(*)[10])a;
//printf("%c\r\n",(*p)[1]);


//error
//char a[10] = "123456";
//char (*p)[10];
//p = a;
//printf("%c\r\n",p[1]);


//correct
//char a[10] = "123456";
//char *p;
//p = a;
//printf("%c\r\n",p[1]);
}


void te_function(void)
{
printf("te_function is called !\r\n");
}


void te_fun_ptr(void)
{
//correct
//void (*pfun)(void);
//pfun = te_function;
//pfun();


//correct
void (*pfun)(void);
pfun = &te_function;
(*pfun)();


//correct
//void (*pfun)(void);
//pfun = te_function;
//(*pfun)();


//correct
//void (*pfun)(void);
//pfun = &te_function;
//pfun();
}


int main(int argc, char* argv[])
{
te_array_ptr();
te_fun_ptr();
printf("Hello World!\n");
while(1);
return 0;
}