📄 page_711.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_711</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_710.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_711</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_712.html">next page ></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 711</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0" width="100%"><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 align="center"><font face="Times New Roman, Times, Serif" size="3"><img src="07dc176d6329a7cbd1a6ac51dab05283.gif" border="0" alt="0711-01.gif" width="535" height="248" /></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" width="100%"><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 align="center"><font face="Times New Roman, Times, Serif" size="2">Figure聽13-3<br /></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hiTemp</font><font face="Times New Roman, Times, Serif" size="2">聽Array聽(Alternate聽Form)</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, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hiTemp</font><font face="Times New Roman, Times, Serif" size="3"> is declared the same as before, but we use an expression of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DayType</font><font face="Times New Roman, Times, Serif" size="3"> for the column index. </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hiTemp[2][SUNDAY]</font><font face="Times New Roman, Times, Serif" size="3"> corresponds to the same component as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hiTemp[2][6]</font><font face="Times New Roman, Times, Serif" size="3"> in the first example. (Recall that enumerators such as </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">MONDAY</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TUESDAY</font><font face="Times New Roman, Times, Serif" size="3">, are represented internally as the integers 0, 1, 2, .) If day were of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DayType</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">week</font><font face="Times New Roman, Times, Serif" size="3"> of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">int</font><font face="Times New Roman, Times, Serif" size="3">, the code fragment shown in Figure 13-3 would set the entire array to 0. (Notice that by using </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DayType</font><font face="Times New Roman, Times, Serif" size="3">, the temperature values in the array begin with the first Monday of the year, not necessarily with January 1.)</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">If the declaration of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">hiTemp</font><font face="Times New Roman, Times, Serif" size="3"> listed the sizes of the two dimensions in reverse order, the rows and columns would be reversed; that is, the declaration</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">int聽hiTemp[7][52];</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">declares an array like that shown in Figure 13-4. Notice how the code fragment in this figure differs from the equivalent code in Figure 13-3: the two index expressions are reversed. The order in which we define the rows and columns doesn't matter to the computer as long as we're consistent. To help visualize a two-dimensional array, we always use the convention of letting the first dimension define the rows and the second dimension define the columns.</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">Another way of looking at a two-dimensional array is to see it as a structure in which each component has two features. For example, in the following code,</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_710.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_711</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_712.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -