第5章数组(Arrays) 5.1数组的概念 5.2一维数组的定义和引用 5.3二维数组的定义和引用 5.4用数组名作函数参数 5.5字符数组 *5.6C++处理字符串的方法一字符串类与字 符串变量 2017年4月26日12时17分 2 HOM正 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 2 5.1 数组的概念 5.2 一维数组的定义和引用 5.3 二维数组的定义和引用 5.4 用数组名作函数参数 5.5 字符数组 *5.6 C++处理字符串的方法——字符串类与字 符串变量
Definition Array is an aggregation including a certain sequential and same type variables.These variables are called elements of the array which have the same data type. Array belongs to tectonic type,and can represent each element exclusively with uniform array name and subscript. 017年4月26日12时17分 HOME 第5章数组 3 BACK NEX
HOME2017年4月26日12时17分 第5章 数组 3 Array is an aggregation including a certain sequential and same type variables. These variables are called elements of the array which have the same data type. Array belongs to tectonic type, and can represent each element exclusively with uniform array name and subscript
Declaration and Reference of 1-dimension array Declaration 类型标识符 数组名[常量表达式]; For example:int a[10]; -“a”is an integer array with ten elements of a[o]to a[9] Reference 数组名[下标] Declared firstly then used and only can be reference one by one. 017年4月26日12时17分 HOME 第5章数组 BACK NEX
HOME2017年4月26日12时17分 第5章 数组 4 • Declaration • 类型标识符 数组名 [常量表达式]; • For example: int a[10]; – “a” is an integer array with ten elements of a[0] to a[9] • Reference • 数组名[下标] – Declared firstly then used , and only can be reference one by one
Storage order of 1-dimension array Array elements are stored in succession, and their address is continuous. For example: a a[0]a[1]a[2]a[3] a[4] a[5]a[6]a[7] a[8]a[9] Note:Array name is memory address of the first array element,so it is a constant and can't be valuated. C++does not allow the dynamic definition of the array size 017年4月26日12时17分 第5章数组 5 HOM BACK NEX
HOME2017年4月26日12时17分 第5章 数组 5 Array elements are stored in succession, and their address is continuous. For example: Note: Array name is memory address of the first array element, so it is a constant and can’t be valuated. C + + does not allow the dynamic definition of the array size . a a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9]
例5.1数组元素的引用 #include <iostream> using namespace std; int main() { int i,a[10]; for(=0;i<=9;i++) a叮=i; for(i=9;i>=0;i-) cout<<a[叮<<""; cout<<endl; return 0; 2017年4月26日12时17分 6 HOM正 第5章数组 BACK NEXT
HOME2017年4月26日12时17分 第5章 数组 6 #include <iostream> using namespace std; int main( ) { int i,a[10]; for (i=0;i<=9;i++) a[i]=i; for (i=9;i>=0;i--) cout<<a[i]<<" "; cout<<endl; return 0; }