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

📄 page_610.html

📁 Programming and Problem Solving with C++
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">	<html>		<head>			<title>page_610</title>			<link rel="stylesheet" href="reset.css" type="text/css" media="all">			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />		</head>		<body>		<table summary="top nav" border="0" width="100%">			<tr>				<td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_609.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_610</strong></td>				<td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_611.html">next page&nbsp;&gt;</a></td>			</tr>					<tr>				<td align="left" colspan="3" style="background: #ffffff; padding: 20px;">    <table border="0" width="100%" cellpadding="0"><tr><td align="center">  <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td>  <td align="right"></td>  </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 610</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">聽聽聽聽聽聽聽聽destination[i]聽=聽source[i];<br />}</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">The word </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">const</font><font face="Times New Roman, Times, Serif" size="3"> guarantees that any attempt to modify the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">source</font><font face="Times New Roman, Times, Serif" size="3"> array within the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Copy</font><font face="Times New Roman, Times, Serif" size="3"> function results in a compile-time error.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">Here's a table that summarizes parameter passage for simple variables and one-dimensional arrays:</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" width="518" cellpadding="7"><tr><td valign="bottom"><font face="Times New Roman, Times, Serif" size="2"><i>Parameter</i></font></td><td valign="bottom"><font face="Times New Roman, Times, Serif" size="2"><i>Formal Parameter<br />Declaration<br />for Pass-by-Value</i></font></td><td valign="bottom"><font face="Times New Roman, Times, Serif" size="2"><i>Formal Parameter<br />Declaration<br />for Pass-by-Reference</i></font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Simple variable</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">int cost</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">int&amp; price</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Array</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Impossible*</font></td><td valign="top"><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">int arr[]</font></td></tr><tr><td colspan="3" valign="top"><font face="Times New Roman, Times, Serif" size="2">*However, prefixing the array declaration with the word </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">const</font><font face="Times New Roman, Times, Serif" size="2"> prevents the function from modifying the parameter.</font></td></tr></table></td></tr></table><br /><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">One final remark about parameter passage: It is a common mistake to pass an array <i>element</i> to a function when passing the entire array was intended. For example, our </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ZeroOut</font><font face="Times New Roman, Times, Serif" size="3"> function expects the base address of a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">float</font><font face="Times New Roman, Times, Serif" size="3"> array to be sent as the first parameter. In the following code fragment, the function call is an error.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">float聽velocity[30];<br />聽聽.<br />聽聽.<br />聽聽.<br />ZeroOut(velocity[30],聽30);聽聽聽聽//聽No</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">First of all, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">velocity[30]</font><font face="Times New Roman, Times, Serif" size="3"> denotes a single array element-one floating point number-and not an entire array. Worse yet, there is no array element with an index of 30. The indices for the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">velocity</font><font face="Times New Roman, Times, Serif" size="3"> array run from 0 through 29.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="17"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">Processing Arrays</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td>  <td colspan="3" height="12"></td>  <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td>  <td><font face="Times New Roman, Times, Serif" size="3">Three types of array processing occur especially often: using part of the declared array (a subarray), using two or more arrays in parallel (parallel arrays), and using index values that have specific meaning within the problem (indices with semantic content). We describe each of these methods briefly here, and leave further examples to the case studies at the end of the chapter.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><p><font size="0"></font></p>  </td>			</tr>				<tr>				<td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_609.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_610</strong></td>				<td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_611.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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