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

📄 page_977.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_977</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_976.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_977</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_978.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 977</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">聽聽聽聽float聽velocity[30];<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽ZeroOut(velocity,聽30);<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<br />聽聽聽聽聽聽.<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">In the function call, the first parameteran array name without index bracketsis a pointer expression. The value of this expression is the base address of 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. This base address is passed to the function. We can write the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ZeroOut</font><font face="Times New Roman, Times, Serif" size="3"> function in one of two ways. The first approachone that you have seen many timesdeclares the first formal parameter to be an array of unspecified size.</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">void聽ZeroOut(聽/*聽out聽*/聽float聽arr[],<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽聽int聽聽聽size聽)<br />{<br />聽聽聽聽int聽i;<br /><br />聽聽聽聽for聽(i聽=聽0;聽i聽&lt;聽size;聽i++)<br />聽聽聽聽聽聽聽聽arr[i]聽=聽0.0;<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">Alternatively, we can declare the formal parameter to be of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">float*</font><font face="Times New Roman, Times, Serif" size="3">, because the parameter simply holds the 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"> variable (the address of the first array element).</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">void聽ZeroOut(聽/*聽out聽*/聽float*聽arr,<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽聽int聽聽聽聽size聽)<br />{<br />聽聽聽聽.<br />聽聽聽聽.<br />聽聽聽聽.聽聽聽//聽Function聽body聽is聽unchanged<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">Whether we declare the formal parameter as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">float聽arr[]</font><font face="Times New Roman, Times, Serif" size="3"> or as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">float*arr</font><font face="Times New Roman, Times, Serif" size="3">, the result is exactly the same to the C++ compiler: within the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ZeroOut</font><font face="Times New Roman, Times, Serif" size="3"> function, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">arr</font><font face="Times New Roman, Times, Serif" size="3"> is a simple variable that points to the beginning of the caller's actual array (see Figure 17-5).</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">Even though </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">arr</font><font face="Times New Roman, Times, Serif" size="3"> is a pointer variable within the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ZeroOut</font><font face="Times New Roman, Times, Serif" size="3"> function, we are still allowed to attach an index expression to the name </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">arr</font><font face="Times New Roman, Times, Serif" size="3">:</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">arr[i]聽=聽0.0;</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_976.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_977</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_978.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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