例如:
struct component
{
int a;
int b;
int c;
};
struct component s1,s2,s3;
struct component * const test1[] =
{
&s1,
&s2,
&s3,
};
const struct component * test2[] =
{
(const struct component *)&s1,
(const struct component *)&s2,
(const struct component *)&s3,
};
const struct component * const test3[] =
{
(const struct component *)&s1,
(const struct component *)&s2,
(const struct component *)&s3,
};
上面的示例程序中test1数组是以常量存储的,叫做常指针数组。而test2则是以变量存储的,并且两者存储的数据的类型是不一样的,test1存储的是struct component *类型的数据,而test2存储的是 const struct component *类型的数据。test3则是内部数据为const struct component *类型数据的常量。
非指针变量的数组定义不一样:
const int a[10];
int const b[10];
上例中a和b都是以常量存储的,而且a和b中的数据都是const类型的int数据。