鹰之歌

既然你崇拜鹰,就要像鹰一样翱翔天际,俯瞰大地。哪怕会摔的粉身碎骨。

导航

数组和指针

情况一:

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;

}

结果:编译通过,运行时错误。

情况三:定义为

posted on 2011-05-27 16:54  鹰之歌  阅读(145)  评论(0编辑  收藏  举报