文档介绍:C++ C++ 程序设计程序设计第六章第六章数组、指针与字符串数组、指针与字符串 Evaluation only. Evaluation only. Created with Client Profile . Created with Client Profile . Copyright 2004-2011 Aspose Pty Ltd. Copyright 2004-2011 Aspose Pty Ltd. 数组的概念数组的概念 数组是具有一定顺序关系的若干相同类型变量的集合体,组成数组的变量称为该数组的元素。 数组属于构造类型。 Evaluation only. Evaluation only. Created with Client Profile . Created with Client Profile . Copyright 2004-2011 Aspose Pty Ltd. Copyright 2004-2011 Aspose Pty Ltd. 一维数组的声明与引用一维数组的声明与引用一维数组的声明类型说明符数组名[ 常量表达式 ]; 例如: int a[10]; 表示 a 为整型数组,有 10 个元素: a[0]...a[9] 引用:必须先声明,后使用。只能逐个引用数组元素,而不能一次引用整个数组! 例如: a[0]=a[5]+a[7]-a[2 * 3] Evaluation only. Evaluation only. Created with Client Profile . Created with Client Profile . Copyright 2004-2011 Aspose Pty Ltd. Copyright 2004-2011 Aspose Pty Ltd. // 数组元素的使用#include <> void main() { double a[3] ; a[0] = ; a[1] = ; a[2] = ; cout << "a[0] = " << a[0] << endl ; cout << "a[1] = " << a[1] << endl ; cout << "a[2] = " << a[2] << endl ; cout << "a[0] + a[1] + a[2] = " << a[0] + a[1] + a[2] << endl ; }/**********程序运行结果********** a[0] = a[1] = a[2] = a[0] + a[1] + a[2] = ************程序结束************/ Evaluation only. Evaluation only. Created with Client Profile . Created with Client Profile . Copyright 2004-2011 Aspose Pty Ltd. Copyright 2004-2011 Aspose Pty Ltd. 一维数组的存储顺序一维数组的存储顺序 数组元素在内存中顺次存放,它们的地址是连续的。例如:具有 10 个元素的数组 a,在内存中的存放次序如下: 数组名字是数组首元素的内存地址。 数组名是一个常量,不能被赋值。 a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[9] a Evaluation only. Evaluation only. Created with Client Profile . Created with Client Profile . Copyright 2004-2011 Aspos