通过指针引用数组
数组元素的指针
数组指针:数组中的第一个元素的地址,也就是数组的首地址。
指针数组:用来存放数组元素地址的数组,称之为指针数组。

注意:虽然我们定义了一个指针变量接收了数组地址,但不能理解为指针变量指向了数组,而应该理 解为指向了数组的元素。
指针的运算
指针运算:指针变量必须要指向数组的某个元素。


案例1:

案例2:


数组名做函数参数
表现形式:
-
形参和实参都用数组名
-
实参用数组名,形参用指针变量
-
实参形参都用指针变量

- 实参为指针变量,形参为数组名
案例1:


数组指针
数组指针:指向一维数组的指针变量。
数组指针定义:假定该指针变量指向具有N个元素的一维数组,则数组指针变量定义如下:

一维数组:

二维数组:

分析:

案例:


案例:

函数的传参
值传递:一般发生在函数形参的类型为char、short、int、long、float、double这样的类型,它的传 递,一般是实参将自己的值复制一份给形参,也就是实参变量和形参变量的变量空间是分开的。此 时形参无法改变实参的数据。
引用传递:一般发生在函数形参的类型为数组、指针这样的类型,它的传递,一般是实参将自己的 内存首地址复制一份给形参,也就是实参变量和形参变量对应内存空间是同一个。此时形参可以改 变实参的数据。