⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right2-3-2.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
📖 第 1 页 / 共 2 页
字号:
a=a[0]=&amp;a[0][0] <font LANG="ZH-CN">其中</font>&amp;<font LANG="ZH-CN">是取地址运算符,</font>&amp;a[0][0]<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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
a[1]=&amp;a[1][0]</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
a[2]=&amp;a[2][0]</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>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[2][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>2<font LANG="ZH-CN">×</font>3<font LANG="ZH-CN">×</font>4=24<font LANG="ZH-CN">个元素。元素排列的规则是:第一维的下标变化最慢,最右边的变化最快。</font></font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">2.   
二维数组的引用</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">C++<font LANG="ZH-CN">语言规定,不能引用整个数组,只能逐个引用元素,元素引用方式为:</font></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></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: 200%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="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>4<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: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};</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>1<font LANG="ZH-CN">个大括弧中数据赋给二维数组的第</font>0<font LANG="ZH-CN">行,把第</font>2<font LANG="ZH-CN">个大括弧中数据赋给二维数组的第</font>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 size="2"><font LANG="ZH-CN">②</font> 
<font LANG="ZH-CN">全部数据写在一个大括号内,例如:</font></font></p>  
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};</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>
<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: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[3][4] = {{1},{5},{9<font LANG="ZH-CN">,</font>10}};</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>1<font LANG="ZH-CN">赋值给</font>a[0][0]<font LANG="ZH-CN">,将</font>5<font LANG="ZH-CN">赋值给</font>a[1][0]<font LANG="ZH-CN">,将</font>9<font LANG="ZH-CN">赋值给</font>a[2][0]<font LANG="ZH-CN">,将</font>10<font LANG="ZH-CN">赋值给</font>a[2][1]<font LANG="ZH-CN">,数组的其它元素赋值为</font>0<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: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[][4]={1,2,3,4,5,6,7,8,9,10,11,12};</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>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};</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>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
int a[][4]={{0,1,2},{ },{7,8,9}};</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<font LANG="ZH-CN">行</font>4<font LANG="ZH-CN">列。</font></font></p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left"> </p>

<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp; <span style="position: absolute; left: 31; top: 1176"><a href="right2-3.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="position: absolute; left: 489; top: 1176"><a href="right2-3-3.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>    

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -