请教: 关于返回指针数组的指针的问题
请问第2种写法为什么是错误的, 只能用第1种写法吗? 谢谢!NO.1
程序代码:
#include <stdio.h> char** name(int *pn) { static char* a[] = { "Jan","Feb","Mar","Apr","May","Jun","Juy" }; *pn = sizeof(a) / sizeof(a[0]); return a; } void main() { int pn; char** p; p = name(&pn); while(pn-->0) printf("%s\n",*p++ ); }
No.2
程序代码:
#include <stdio.h> char(*name(int* pn))[] { static char* a[] = { "Jan","Feb","Mar","Apr","May","Jun","Juy" }; *pn = sizeof(a) / sizeof(a[0]); return a; } void main() { int pn; char (*p)[]; p = name(&pn); while (pn-- > 0) printf("%s\n", *p++); }