我编写了一个简单的 C 程序来学习函数指针的用法:
#include <stdio.h>
int (*workA) ( char *vA );
int (*workB) ( char *vB );
int main( int argc, char * argv[] )
{
char *strA = "Hello.";
char *strB = "Bonjour.";
int a = workA(strA);
int b = workB(strB);
printf("Return value of A = %d, B = %d.\n", a, b);
return 0;
}
int (*workA)( char *vA )
{
printf("A: %s\n", vA); // line 20
return 'A';
}
int (*workB)( char *vB )
{
printf("B: %s\n", vB); // line 27
return 'B';
}
海合会抱怨:
test.c:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
test.c:27: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
我不知道它有什么问题。任何意见将不胜感激。