📄 7.3.2.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<body>
<table align="right" width="300">
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.1b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.2b.htm'" ></td>
</tr>
</table>
<p><br>
<br>
<font class="title2"><b>7.3.2 数组元素地址分配</b></font> </p>
<table>
<tr>
<td> </td>
<td class="content">若数组A的元素存放在一片连续单元里,且每个元素域宽为w
,则A的下标为i的元素的开始地址为 <p> base+(i-low
)* w (7.3) </p>
<p>其中low为数组下标的下界并且base是数组存储位置的相对地址,即base为A的第一个元素A[low]的相对地址。
</p>
<p>重写(7.3)式为: </p>
<p> i * w+(base-low* w) </p>
<p>则其中子表达式c=base-low * w可以在编译时计算出来。我们假定c之存放在符号表中数组A的表项里,则相对地址A[i]的计算就为i
* w +c。 </p>
<p>对于一个二维数组,可以按行或按列存放。如对于2*3的数组A,图7.9(a)是将它按行存放,图7.9(b)是将它按列存放。若二维数组A按行存放,则可用如下公式计算A[i<span
class="down"><sub>1</sub>,i<sub>2</sub>]
的相对地址: </p>
<p> base +((i<sub>1</sub> 一low<span
class="down"><sub>1</sub>)* n<sub>2</sub>+i<span
class="down"><sub>2</sub> 一low<sub>2</sub>)*w) </p>
</td>
</tr>
<tr>
<td></td>
<td class="content"></td>
</tr>
</table>
<p align="center"><img src="7_91.gif" width="331" height="221" alt="7_91.gif (2758 bytes)"><img
src="7_92.gif" width="426" height="221" alt="7_92.gif (2965 bytes)"><br>
图7.9 二维数组的存放方式</p>
<table align="right" width="300">
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.1b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.3.2b.htm'" ></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -