c语言 数组类型

数组类型重命名
数组类型由元素类型和数组大小共同决定
数组指针是一个指针,只想对应类型的数组
指针数组是一个数组,其中每个元素都是指针
数组指针遵循指针运算法则
指针数组拥有c语言数组的各种特性

c通过typedef 为数组类型重命名
格式为 typedef type(name)[size]

数组类型:
typedef int(aint5)[5]
typedef float(afloat10)[10]

数组定义:
aint5 iarray; //定义了一个数组
afloat10 farray; //定义了一个数组

数组指针:
aint5* parray;
afloat10* parray;

直接定义:
type(*pointer)[n]; //pointer 是一个指针,type代表指向的数组的类型,n为指向的数组的大小。


code:

#include <stdio.h>
typedef int(AINT5)[5];
typedef float(AFLOAT10)[10];
typedef char(ACHAR9)[9];
int main()
{
AINT5 a1;
float fArray[10];
AFLOAT10* pf = &fArray;
ACHAR9 cArray;
char(*pc)[9] = &cArray;
float(*pcw)[10] = &fArray;
int i = 0;
printf("%d, %d
", sizeof(AINT5), sizeof(a1));
for(i=0; i<10; i++)
{
(*pf)[i] = i;
}
for(i=0; i<10; i++)
{
printf("%f
", fArray[i]);
}
printf("%p, %p, %p
", &cArray, pc+1, pcw+1);
return 0;
}
原文地址:https://www.cnblogs.com/sea-stream/p/10994952.html