📄 right2-3-2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 2 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 4; top: -8"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">
<span style="background-color: #CCFF99">第 2 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 3 节 </span>><span style="background-color: #CCFF99">
2.3.2 二维数组</span></p>
<hr color="#008000" size="1">
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2">1.
<font LANG="ZH-CN">定义二维数组</font></font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">定义二维数组的语法格式为:</font></p>
<blockquote>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000"><font LANG="ZH-CN">类型标识符</font>
<font LANG="ZH-CN">数组名</font>[<font LANG="ZH-CN">常量表达式</font>][<font LANG="ZH-CN">常量表达式</font>];</font></p>
</blockquote>
</blockquote>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font LANG="ZH-CN" size="2">例如:</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">
int a[3][4];</font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">定义了一个整型二维数组</font>a<font LANG="ZH-CN">,共有</font>3*4=12<font LANG="ZH-CN">个元素,可以称为</font>3<font LANG="ZH-CN">行</font>4<font LANG="ZH-CN">列的数组。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">说明:</font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">①</font>
<font LANG="ZH-CN">二维数组中每一个元素必须有两个下标。</font></font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">②</font>
<font LANG="ZH-CN">可以将二维数组元素排列成一个矩阵,用二维数组的第</font>1<font LANG="ZH-CN">个下标表示数组元素所在的行,第</font>2<font LANG="ZH-CN">个下标表示所在的列。</font></font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">③</font>
C++<font LANG="ZH-CN">语言中,二维数组中元素排列的顺序是:按行存放,即在内存中先顺序存放第一行的元素,再存放第二行的元素。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">例如数组</font>a[3][4]<font LANG="ZH-CN">的存放顺序是:</font>a[0][0]<font LANG="ZH-CN">、</font>a[0][1]<font LANG="ZH-CN">、</font>a[0][2]<font LANG="ZH-CN">、</font>a[0][3]<font LANG="ZH-CN">、</font>a[1][0]<font LANG="ZH-CN">、</font>a[1][1]<font LANG="ZH-CN">、</font>a[1][2]<font LANG="ZH-CN">、</font>a[1][3]<font LANG="ZH-CN">、</font>a[2][0]<font LANG="ZH-CN">、</font>a[2][1]<font LANG="ZH-CN">、</font>a[2][2]<font LANG="ZH-CN">、</font>a[2][3]<font LANG="ZH-CN">。</font></font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">④</font>
<font LANG="ZH-CN">二维数组可看成一个一维数组,其中的每一个元素又是一个一维数组。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2"><font LANG="ZH-CN">例如数组</font>a[3][4]<font LANG="ZH-CN">可以看成是一个一维数组,它有</font>3<font LANG="ZH-CN">个元素:</font>a[0]<font LANG="ZH-CN">、</font>a[1]<font LANG="ZH-CN">、</font>a[2]<font LANG="ZH-CN">,每一个元素又是一个包括</font>4<font LANG="ZH-CN">个元素的一维数组,如元素</font>a[0]<font LANG="ZH-CN">有</font>4<font LANG="ZH-CN">个元素</font>a[0][0]<font LANG="ZH-CN">、</font>a[0][1]<font LANG="ZH-CN">、</font>a[0][2]<font LANG="ZH-CN">、</font>a[0][3]<font LANG="ZH-CN">。即:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 10; margin-bottom: 0"><font size="2">
a[0] a[0][0] a[0][1] a[0][2] a[0][3]</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">
a[1] a[1][0] a[1][1] a[1][2] a[1][3]</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 10"><font size="2">
a[2] a[2][0] a[2][1] a[2][2] a[2][3]</font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN"><font face="??ì?,SimSun">⑤
</font>数组名</font>a<font LANG="ZH-CN">表示数组第一个单元</font>a[0][0]<font LANG="ZH-CN">的地址,也就是数组的首地址。</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">a[0]<font LANG="ZH-CN">也表示地址,表示第</font>0<font LANG="ZH-CN">行的首地址,即</font>a[0][0]<font LANG="ZH-CN">的地址;</font>a[1]<font LANG="ZH-CN">表示第</font>1<font LANG="ZH-CN">行的首地址,即</font>a[1][0]<font LANG="ZH-CN">的地址;</font>a[2]<font LANG="ZH-CN">表示第</font>2<font LANG="ZH-CN">行的首地址,即</font>a[2][0]<font LANG="ZH-CN">的地址。因此可以得到下面的关系:</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -