在vc中编译c的代码,为什么不能使用int *类型的指针呢?

来源:百度知道 编辑:UC知道 时间:2024/05/14 06:55:55
#include <stdio.h>
int main(){
int a[3];
a[0]=0;
a[1]=1;
a[2]=2;
int *p;
int *q;
p=a;
q=&a[2];
printf("%d",a[q-p]);
}

---
Compiling...
test.c
E:\test1\terst\test.c(7) : error C2143: syntax error : missing ';' before 'type'
E:\test1\terst\test.c(8) : error C2143: syntax error : missing ';' before 'type'
E:\test1\terst\test.c(9) : error C2065: 'p' : undeclared identifier
E:\test1\terst\test.c(9) : warning C4047: '=' : 'int ' differs in levels of indirection from 'int *'
E:\test1\terst\test.c(10) : error C2065: 'q' : undeclared identifier
E:\test1\terst\test.c(10) : warning C4047: '=' : 'int ' differs in levels of indirection from 'int *'

为什么不能识别int *

原因,C语言的变量定义只能在函数的最前面.
#include <stdio.h>
int main(){
int *p;
int *q;
int a[3];
a[0]=0;
a[1]=1;
a[2]=2;

p=a;
q=&a[2];
printf("%d",a[q-p]);
}

然也。