数组和指针
情况一:
a.cpp:
int test[3]={1,2,3};
b.cpp:
#include<iostream.h>
extern int test[];
void main()
{
cout<<test[2]<<endl;
}
运行结果正确,打印test[2],即3到标准输出。
情况二:定义为数组,以指针方式引用
a.cpp:
int test[3]={1,2,3};
b.cpp:
#include<iostream.h>
//extern int test[];
extern int *test;
void main()
{
cout<<test[2]<<endl;
}
结果:编译通过,运行时错误。
情况三:定义为
浙公网安备 33010602011771号