指针数组与数组指针
来源:互联网 发布:哪个软件看泰剧最全 编辑:程序博客网 时间:2024/06/08 06:15
c语言中的数组有自己特 定的类型
数组的类型由元素类型和数组大小共同决定 如:int array[5]的类型为int[5]
定义数组类型:
通过typedet type(name)[size];为数组类型重命名
数组类型:typedef int(AINT5) 【5】;
则数组定义为:AINT5 array;
数组指针用于指向一个数组
#include<stdio.h>typedef int(AINT5) [5];typedef float(AFLOAT10) [10];typqdef char(ACHAR9) [9]; int main(){AINT5 a1;float fArray[10];AFLOAT10* pf=&fArray;ACHAR cArray;char(*pc)[9]=&cArray;char(*pw)[4]=cArray; //error:这用用一个指向数组的指针去指向一个char类型的地址,这是不合法的!!!
int i=0;printg("%d , %d\n",sizeof(AINT5),sizeof(a1));//这里算的是算出类型所占用的内存空间的大小,都是20 for(i=0;i<10;i++){(*pf)[i]=i;//等价于fArray[i]=i;}printf("%p,%p,%p",&cArray,pc+1,pw+1);// pc+1===>(unsigned int)pc+sizeof(*pc)==>(unsigned int)pc+9}
数组名是数组首元素的起始地址,但并不是数组的起始地址
通过将取地址符&作用于数组名可以得到数组的起始地址
可通过数组类型定义数组指针:ArrayType* pointer;
也可直接定义:type(*pointer)[n];
pointer为数组指针变量名
type为指向的数组的类型
n为指向的数组的大小
阅读全文
1 0
- 指针:指针与数组
- 指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 数组指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组 与数组指针
- 指针数组与数组指针
- 数组指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- mysql无法启动ERROR! MySQL is running but PID file coul
- 快速幂模板
- Java集合之六Collections工具类
- Java三大器之监听器(Listener)详解
- 数字电路的学习总结
- 指针数组与数组指针
- bzoj1455 罗马游戏【并查集+可并堆】
- Spring Boot核心条件注解
- Web Services入门
- 手机端横竖屏检测
- 哈理工 oj2352Save the Little Ant 【所谓的水题】
- 《日本语能力测试阶梯导学读解专训N2》
- 【笔记】深入理解 java 虚拟机---GC.
- pstree命令乱码问题