#include<stdio.h>
main()
{
char **p;
char a[3][10]={"how old!","ni hao!","zhenbang"}; clrscr();
p=a;
for(;p<=a+2;p++)
printf("%s\n",*p);
}
错在哪里了?为什么老是运行不好!(用turboc2.0运行)
參考答案:首先你的指针p与二维数组名类型不匹配。
p是char型指针的指针,二维数组名是数组指针,指向的数组含10个char
其次,TC里面不支持对非静态数组进行一次性初始化。修改的程序如下
#include<stdio.h>
int
main(void)
{
char (* p)[10];
static char a[3][10] = { "how old!", "ni hao!", "zhenbang" };
clrscr();
for( p = a; p <= a+2; p++ )
printf( "%s\n", *p );
getchar(); /* TC好像是不会自动暂停的 */
return 0;
}