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

📄 right2-4-2.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">&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="background-color: #CCFF99">第 2 章</span><span style="background-color: #CCFF99">&nbsp;                  
</span>&gt;<span style="background-color: #CCFF99"> 第 4 节 </span>&gt;<span style="background-color: #CCFF99"> 
 2.4.2 指针数组和多级指针</span></p>      
<font SIZE="3">
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"></font></p>
<hr color="#008000" size="1">

<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">1.  
指针数组</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">(1)  
<font LANG="ZH-CN">指针数组的概念</font></font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">定义一种特殊的数组,这类数组存放的全部是指针,分别用于指向某类的变量,以替代这些变量在程序中的使用,增加灵活性。</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">(2)  
<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>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">例如:</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
char *str[4];</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">(1)  
<font LANG="ZH-CN">多级指针的概念</font></font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">一个指针变量可以指向整型变量、实型变量、字符类型变量,当然也可以指向指针类型变量。当这种指针变量用于指向指针类型变量时,我们称之为指向指针的指针变量,这话可能会感到有些绕口,但想到一个指针变量的地址就是指向该变量的指针时,这种多级指针的含义就容易理解了。下面用图来描述这种多级指针。</font></font><font SIZE="3">&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;</p>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0">&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; 
<img border="0" src="right21.gif" width="316" height="74"></p>
</font>
<p ALIGN="CENTER" style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font LANG="ZH-CN">从图可以看出指针变量</font>pi<font LANG="ZH-CN">中存放的是整型变量</font>i<font LANG="ZH-CN">的地址,那么指针</font>pi<font LANG="ZH-CN">就指向</font>i<font LANG="ZH-CN">。同理指针</font>p<font LANG="ZH-CN">指向整型变量</font>x<font LANG="ZH-CN">,指针</font>pp<font LANG="ZH-CN">指向指针变量</font>p<font LANG="ZH-CN">。这里指针</font>pp<font LANG="ZH-CN">就是一个二级指针,它不直接指向一个普通变量,而是指向一个指针变量,指针变量指向一个普通变量。当然还有可能出现三级或四级指针,鉴于它们的复杂性,本节只是介绍二级指针。多级指针可以增加操作的灵活性,但是也会相应增加难度。</font></font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">(2)  
<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></p> 
  </blockquote>
</blockquote>
<p ALIGN="JUSTIFY" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font LANG="ZH-CN" size="2">例如:</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
float **ptr;</font> 
<font SIZE="3">
</p>
</font>

<hr size="1" color="#008000">
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;&nbsp; <span style="position: absolute; left: 33; top: 736"><a href="right2-4.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: 492; top: 740"><a href="right2-5.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 + -