此题是老师提供的程序但是在VC6.0下运行出错了。
小的实在看不出来哪错了。求大神指点迷津。
附程序如下:
#include <stdio.h>
void main()
{
int a[]={2,3,4,5,6};
int *p1;
p1=a;
printf("%d\n",p1+2);
printf("%d\n",*(p1+2)); p1=a+2;
printf("%d\n",p1+2);
printf("%d\n",*(p1+2)); char *p2="computer\n";
printf(p2+2);
printf("%s",p2+2);
}
以及错误如下:
D:\c语言\lab7_1.c(14) : error C2143: syntax error : missing ';' before 'type'
D:\c语言\lab7_1.c(15) : error C2065: 'p2' : undeclared identifier
D:\c语言\lab7_1.c(15) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\c语言\lab7_1.c(15) : warning C4024: 'printf' : different types for formal and actual parameter 1
执行 cl.exe 时出错. lab7_1.obj - 1 error(s), 0 warning(s)
小的实在看不出来哪错了。求大神指点迷津。
附程序如下:
#include <stdio.h>
void main()
{
int a[]={2,3,4,5,6};
int *p1;
p1=a;
printf("%d\n",p1+2);
printf("%d\n",*(p1+2)); p1=a+2;
printf("%d\n",p1+2);
printf("%d\n",*(p1+2)); char *p2="computer\n";
printf(p2+2);
printf("%s",p2+2);
}
以及错误如下:
D:\c语言\lab7_1.c(14) : error C2143: syntax error : missing ';' before 'type'
D:\c语言\lab7_1.c(15) : error C2065: 'p2' : undeclared identifier
D:\c语言\lab7_1.c(15) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\c语言\lab7_1.c(15) : warning C4024: 'printf' : different types for formal and actual parameter 1
执行 cl.exe 时出错. lab7_1.obj - 1 error(s), 0 warning(s)