亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch11.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
For example,</P>
<PRE><FONT COLOR="#0066FF">SQUARE Board[64]
</FONT></PRE>
<P>This doesn't correspond as closely to the real-world object as the two-dimension.
When the game begins, the king is located in the fourth position in the first row.
Counting from zero array, that position corresponds to</P>
<PRE><FONT COLOR="#0066FF">Board[0][3];
</FONT></PRE>
<P>assuming that the first subscript corresponds to <TT>row</TT>, and the second
to <TT>column</TT>. The layout of positions for the entire board is illustrated in
Figure 11.3.<BR>
<BR>
<A NAME="Heading22"></A><A HREF="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp03.jpg  \n\nThis file was not retrieved by Teleport Pro, because the server reports that this file cannot be found.  \n\nDo you want to open it from the server?'))window.location='http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp03.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp03.jpg"><FONT COLOR="#000077">Figure
11.3.</FONT></A><FONT COLOR="#000077"><I> </I></FONT><I>A chess board and a two-dimensional
array.</I>
<H3 ALIGN="CENTER"><A NAME="Heading23"></A><FONT COLOR="#000077">Initializing Multidimensional
Arrays</FONT></H3>
<P>You can initialize multidimensional arrays. You assign the list of values to array
elements in order, with the last array subscript changing while each of the former
holds steady. Therefore, if you have an array</P>
<PRE><FONT COLOR="#0066FF">int theArray[5][3]
</FONT></PRE>
<P>the first three elements go into <TT>theArray[0]</TT>; the next three into <TT>theArray[1]</TT>;
and so forth.</P>
<P>You initialize this array by writing</P>
<PRE><FONT COLOR="#0066FF">int theArray[5][3] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }
</FONT></PRE>
<P>For the sake of clarity, you could group the initializations with braces. For
example,</P>
<PRE><FONT COLOR="#0066FF">int theArray[5][3] = {  {1,2,3},
{4,5,6},
{7,8,9},
{10,11,12},
{13,14,15} };
</FONT></PRE>
<P>The compiler ignores the inner braces, which make it easier to understand how
the numbers are distributed.</P>
<P>Each value must be separated by a comma, without regard to the braces. The entire
initialization set must be within braces, and it must end with a semicolon.</P>
<P>Listing 11.5 creates a two-dimensional array. The first dimension is the set of
numbers from 0 to 5. The second dimension consists of the double of each value in
the first dimension.</P>
<P><A NAME="Heading24"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 11.5. Creating
a multidimensional array.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">
1:     #include &lt;iostream.h&gt;
2:     int main()
3:     {
4:        int SomeArray[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8}};
5:        for (int i = 0; i&lt;5; i++)
6:           for (int j=0; j&lt;2; j++)
7:           {
8:              cout &lt;&lt; &quot;SomeArray[&quot; &lt;&lt; i &lt;&lt; &quot;][&quot; &lt;&lt; j &lt;&lt; &quot;]: &quot;;
9:              cout &lt;&lt; SomeArray[i][j]&lt;&lt; endl;
10:          }
11:
12:     return 0;
<TT>13: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: SomeArray[0][0]: 0
SomeArray[0][1]: 0
SomeArray[1][0]: 1
SomeArray[1][1]: 2
SomeArray[2][0]: 2
SomeArray[2][1]: 4
SomeArray[3][0]: 3
SomeArray[3][1]: 6
SomeArray[4][0]: 4
SomeArray[4][1]: 8
</FONT></PRE>
<P><FONT COLOR="#0000AA"><B>Analysis:</B></FONT><B> </B>Line 4 declares <TT>SomeArray</TT>
to be a two-dimensional array. The first dimension consists of five integers; the
second dimension consists of two integers. This creates a 5x2 grid, as Figure 11.4
shows. <BR>
<A HREF="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg  \n\nThis file was not retrieved by Teleport Pro, because the server reports that this file cannot be found.  \n\nDo you want to open it from the server?'))window.location='http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg"><BR>
</A><A NAME="Heading26"></A><A HREF="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg  \n\nThis file was not retrieved by Teleport Pro, because the server reports that this file cannot be found.  \n\nDo you want to open it from the server?'))window.location='http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp04.jpg"><FONT COLOR="#000077">Figure
11.4.</FONT></A><FONT COLOR="#000077"> </FONT><I>A 5x2 array. </I><BR>
<BR>
The values are initialized in pairs, although they could be computed as well. Lines
5 and 6 create a nested <TT>for</TT> loop. The outer <TT>for</TT> loop ticks through
each member of the first dimension. For every member in that dimension, the inner
<TT>for</TT> loop ticks through each member of the second dimension. This is consistent
with the printout. <TT>SomeArray[0][0]</TT> is followed by <TT>SomeArray[0][1]</TT>.
The first dimension is incremented only after the second dimension is incremented
by 1. Then the second dimension starts over.
<H3 ALIGN="CENTER"><A NAME="Heading27"></A><FONT COLOR="#000077">A Word About Memory</FONT></H3>
<P>When you declare an array, you tell the compiler exactly how many objects you
expect to store in it. The compiler sets aside memory for all the objects, even if
you never use it. This isn't a problem with arrays for which you have a good idea
of how many objects you'll need. For example, a chess board has 64 squares, and cats
have between 1 and 10 kittens. When you have no idea of how many objects you'll need,
however, you must use more advanced data structures.</P>
<P>This book looks at arrays of pointers, arrays built on the free store, and various
other collections. Other more advanced data structures that solve large data storage
problems are beyond the scope of this book. Two of the great things about programming
are that there are always more things to learn and that there are always more books
from which to learn.
<H3 ALIGN="CENTER"><A NAME="Heading28"></A><FONT COLOR="#000077">Arrays of Pointers</FONT></H3>
<P>The arrays discussed so far store all their members on the stack. Usually stack
memory is severely limited, whereas free store memory is far larger. It is possible
to declare each object on the free store and then to store only a pointer to the
object in the array. This dramatically reduces the amount of stack memory used. Listing
11.6 rewrites the array from Listing 11.4, but it stores all the objects on the free
store. As an indication of the greater memory that this enables, the array is expanded
from 5 to 500, and the name is changed from <TT>Litter</TT> to <TT>Family</TT>.</P>
<P><A NAME="Heading29"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 11.6. Storing
an array on the free store.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">
1:     // Listing 11.6 - An array of pointers to objects
2:
3:     #include &lt;iostream.h&gt;
4:
5:     class CAT
6:     {
7:        public:
8:           CAT() { itsAge = 1; itsWeight=5; }   
9:           ~CAT() {}                                 // destructor
10:          int GetAge() const { return itsAge; }
11:          int GetWeight() const { return itsWeight; }
12:          void SetAge(int age) { itsAge = age; }
13:
14:       private:
15:          int itsAge;
16:          int itsWeight;
17:    };
18:
19:    int main()
20:    {
21:       CAT * Family[500];
22:       int i;
23:       CAT * pCat;
24:       for (i = 0; i &lt; 500; i++)
25:       {
26:          pCat = new CAT;
27:          pCat-&gt;SetAge(2*i +1);
28:          Family[i] = pCat;
29:       }
30:
31:       for (i = 0; i &lt; 500; i++)
32:       {
33:          cout &lt;&lt; &quot;Cat #&quot; &lt;&lt; i+1 &lt;&lt; &quot;: &quot;;
34:          cout &lt;&lt; Family[i]-&gt;GetAge() &lt;&lt; endl;
35:       }
36:     return 0;
<TT>37: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: Cat #1: 1
Cat #2: 3
Cat #3: 5
...
Cat #499: 997
Cat #500: 999</FONT></PRE>

<DL>
	<DD><FONT COLOR="#0066FF"></FONT>
</DL>

<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The <TT>CAT</TT> object declared
in lines 5-17 is identical with the <TT>CAT</TT> object declared in Listing 11.4.
This time, however, the array declared in line 21 is named <TT>Family</TT>, and it
is declared to hold 500 pointers to <TT>CAT</TT> objects.</P>
<P>In the initial loop (lines 24-29), 500 new <TT>CAT</TT> objects are created on
the free store, and each one has its age set to twice the index plus one. Therefore,
the first <TT>CAT</TT> is set to <TT>1</TT>, the second <TT>CAT</TT> to <TT>3</TT>,
the third <TT>CAT</TT> to <TT>5</TT>, and so on. Finally, the pointer is added to
the array.</P>
<P>Because the array has been declared to hold pointers, the pointer--rather than
the dereferenced value in the pointer--is added to the array.</P>
<P>The second loop (lines 31 and 32) prints each of the values. The pointer is accessed
by using the index, <TT>Family[i]</TT>. That address is then used to access the <TT>GetAge()</TT>
method.</P>
<P>In this example, the array <TT>Family</TT> and all its pointers are stored on
the stack, but the 500 <TT>CAT</TT>s that are created are stored on the free store.
<H3 ALIGN="CENTER"><A NAME="Heading31"></A><FONT COLOR="#000077">Declaring Arrays
on the Free Store</FONT></H3>
<P>It is possible to put the entire array on the free store, also known as the heap.
You do this by calling <TT>new</TT> and using the subscript operator. The result
is a pointer to an area on the free store that holds the array. For example,</P>
<PRE><FONT COLOR="#0066FF">CAT *Family = new CAT[500];
</FONT></PRE>
<P>declares <TT>Family</TT> to be a pointer to the first in an array of 500 <TT>CAT</TT>s.
In other words, <TT>Family</TT> points to--or has the address of--<TT>Family[0]</TT>.</P>
<P>The advantage of using <TT>Family</TT> in this way is that you can use pointer
arithmetic to access each member of <TT>Family</TT>. For example, you can write</P>
<PRE><FONT COLOR="#0066FF">CAT *Family = new CAT[500];
CAT *pCat = Family;              //pCat points to Family[0]
pCat-&gt;SetAge(10);                // set Family[0] to 10
pCat++;                          // advance to Family[1]
pCat-&gt;SetAge(20);                // set Family[1] to 20
</FONT></PRE>
<P>This declares a new array of 500 <TT>CAT</TT>s and a pointer to point to the start
of the array. Using that pointer, the first <TT>CAT</TT>'s <TT>SetAge()</TT> function
is called with a value of <TT>10</TT>. The pointer is then incremented to point to
the next <TT>CAT</TT>, and the second <TT>Cat</TT>'s <TT>SetAge()</TT> method is
then called.
<H3 ALIGN="CENTER"><A NAME="Heading32"></A><FONT COLOR="#000077">A Pointer to an
Array Versus an Array of Pointers</FONT></H3>
<P>Examine these three declarations:</P>
<PRE><FONT COLOR="#0066FF">1:  Cat   FamilyOne[500]
2:  CAT * FamilyTwo[500];
3:  CAT * FamilyThree = new CAT[500];
</FONT></PRE>
<P><TT>FamilyOne</TT> is an array of 500 <TT>CAT</TT>s. <TT>FamilyTwo</TT> is an
array of 500 pointers to <TT>CAT</TT>s. <TT>FamilyThree</TT> is a pointer to an array
of 500 <TT>CAT</TT>s.</P>
<P>The differences among these three code lines dramatically affect how these arrays
operate. What is perhaps even more surprising is that <TT>FamilyThree</TT> is a variant
of <TT>FamilyOne</TT>, but is very different from <TT>FamilyTwo</TT>.</P>
<P>This raises the thorny issue of how pointers relate to arrays. In the third case,
<TT>FamilyThree</TT> is a pointer to an array. That is, the address in <TT>FamilyThree</TT>
is the address of the first item in that array. This is exactly the case for <TT>FamilyOne</TT>.
<H3 ALIGN="CENTER"><A NAME="Heading33"></A><FONT COLOR="#000077">Pointers and Array
Names</FONT></H3>
<P>In C++ an array name is a constant pointer to the first element of the array.
Therefore, in the declaration</P>
<PRE><FONT COLOR="#0066FF">CAT Family[50];
</FONT></PRE>
<P><TT>Family</TT> is a pointer to <TT>&amp;Family[0]</TT>, which is the address
of the first element of the array <TT>Family</TT>.</P>
<P>It is legal to use array names as constant pointers, and vice versa. Therefore,
<TT>Family + 4</TT> is a legitimate way of accessing the data at <TT>Family[4]</TT>.</P>
<P>The compiler does all the arithmetic when you add to, increment, and decrement
pointers. The address accessed when you write <TT>Family + 4</TT> isn't 4 bytes past
the address of <TT>Family</TT>--it is four objects. If each object is 4 bytes long,
<TT>Family + 4</TT> is 16 bytes. If each object is a <TT>CAT</TT> that has four <TT>long</TT>
member variables of 4 bytes each and two <TT>short</TT> member variables of 2 bytes
each, each <TT>CAT</TT> is 20 bytes, and <TT>Family + 4</TT> is 80 bytes past the
start of the array.</P>
<P>Listing 11.7 illustrates declaring and using an array on the free store.</P>
<P><A NAME="Heading34"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 11.7. Creating
an array by using new.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">
1:     // Listing 11.7 - An array on the free store
2:
3:     #include &lt;iostream.h&gt;
4:
5:     class CAT
6:     {
7:        public:
8:           CAT() { itsAge = 1; itsWeight=5; } 
9:           ~CAT();         
10:          int GetAge() const { return itsAge; }
11:          int GetWeight() const { return itsWeight; }
12:          void SetAge(int age) { itsAge = age; }
13:
14:       private:
15:          int itsAge;
16:          int itsWeight;
17:    };
18:
19:    CAT :: ~CAT()
20:    {
21:      // cout &lt;&lt; &quot;Destructor called!\n&quot;;
22:    }
23:
24:    int main()
25:    {
26:       CAT * Family = new CAT[500];
27:       int i;
28:       CAT * pCat;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
粉嫩aⅴ一区二区三区四区五区| 欧美一区二区三区色| 欧美人动与zoxxxx乱| 久久久精品免费网站| 亚洲成在人线在线播放| 欧美综合一区二区| 国产精品毛片久久久久久久| 日韩电影在线观看一区| 极品美女销魂一区二区三区| 成a人片国产精品| 国产午夜精品久久| 日韩小视频在线观看专区| 依依成人综合视频| 色美美综合视频| 蜜桃av一区二区| 日韩午夜激情免费电影| 国产一区二区三区精品视频| 国产精品欧美极品| 欧美日韩精品系列| 99视频超级精品| 亚洲区小说区图片区qvod| 亚洲v中文字幕| 亚洲欧洲一区二区三区| 亚洲同性同志一二三专区| 国产精品天天看| 日本成人在线电影网| 成人午夜av电影| 成人av中文字幕| 欧美高清一级片在线| 精品黑人一区二区三区久久| 91黄色激情网站| 91精品综合久久久久久| 欧美日韩高清一区二区不卡| 综合色天天鬼久久鬼色| 欧美精选一区二区| 国产喂奶挤奶一区二区三区| 色婷婷精品久久二区二区蜜臂av| 国产精品一二二区| 色爱区综合激月婷婷| 欧美日韩在线播放三区四区| 日韩一本二本av| 国产精品美女www爽爽爽| 亚洲午夜一二三区视频| 青青草成人在线观看| 成人性视频网站| 91精品国产乱| 日本一区二区三区高清不卡| 亚洲一区二区三区三| 国产成人免费高清| 日韩三级电影网址| 悠悠色在线精品| 国产高清不卡一区二区| 在线成人av网站| 国产精品久久久久一区二区三区| 日韩精品一级中文字幕精品视频免费观看 | 久久精品一级爱片| 一区二区三区成人| www.性欧美| 久久久久久日产精品| 欧美aⅴ一区二区三区视频| 色偷偷久久一区二区三区| 欧美激情一区三区| 国产一区二区网址| 精品国产麻豆免费人成网站| 亚洲一区二区三区激情| 色诱视频网站一区| 1024成人网| av高清不卡在线| 日本一区二区成人在线| 国产一区二区三区黄视频 | 亚洲一区二区四区蜜桃| 粉嫩绯色av一区二区在线观看 | 国产九九视频一区二区三区| 日韩一区二区三区av| 五月天网站亚洲| 777久久久精品| 日韩电影在线免费看| 欧美日本一区二区三区| 日韩在线卡一卡二| 日韩三级电影网址| 麻豆精品一区二区av白丝在线| 91精品国产综合久久久蜜臀图片 | 国产亚洲精品aa| 国产精品自在在线| 国产精品欧美经典| 91啪亚洲精品| 亚洲成a人片在线不卡一二三区| 欧美日韩免费在线视频| 天涯成人国产亚洲精品一区av| 欧美色中文字幕| 美女免费视频一区二区| 久久精品欧美一区二区三区麻豆| 国产成人小视频| 亚洲精品网站在线观看| 欧美影院精品一区| 久久精品国产久精国产| 国产日韩欧美a| 91视频你懂的| 亚洲风情在线资源站| 91精品国产91久久综合桃花| 国产一区二区免费看| 亚洲欧洲另类国产综合| 一本高清dvd不卡在线观看| 亚洲成人av福利| 久久久久久久综合日本| 波多野结衣在线一区| 亚洲国产一区二区三区青草影视| 日韩精品一区二区三区视频在线观看| 国产一区二区剧情av在线| 国产精品久久影院| 欧美片在线播放| 懂色av一区二区在线播放| 亚洲日本电影在线| 日韩欧美在线一区二区三区| 国产精品亚洲午夜一区二区三区| 国产免费成人在线视频| 欧美日韩色一区| 成人黄色大片在线观看| 美女精品自拍一二三四| 一区二区三区在线视频观看 | 豆国产96在线|亚洲| 午夜精品久久久久久久久久| 国产日韩高清在线| 欧美高清性hdvideosex| 91丝袜呻吟高潮美腿白嫩在线观看| 日本免费在线视频不卡一不卡二| 国产精品网曝门| 久久久三级国产网站| 欧美高清你懂得| 在线精品观看国产| jlzzjlzz欧美大全| 国产精品一二三四五| 麻豆精品在线播放| 日韩精品一级中文字幕精品视频免费观看| 国产精品视频一二三区| 精品福利视频一区二区三区| 7777精品伊人久久久大香线蕉最新版| av爱爱亚洲一区| 成人小视频免费在线观看| 国产在线一区观看| 久久国产精品区| 美腿丝袜亚洲一区| 日韩主播视频在线| 午夜精品一区二区三区三上悠亚| 中文字幕在线视频一区| 中文字幕不卡三区| 久久久99久久精品欧美| 久久久久久亚洲综合影院红桃| 精品国免费一区二区三区| 日韩一区二区三区观看| 日韩一级黄色大片| 欧美成人国产一区二区| 日韩欧美国产一区在线观看| 欧美一区日本一区韩国一区| 91麻豆精品国产91久久久更新时间 | 国内精品不卡在线| 美脚の诱脚舐め脚责91| 视频一区欧美日韩| 亚洲gay无套男同| 爽好久久久欧美精品| 蜜臀av一级做a爰片久久| 欧美a级一区二区| 国产在线不卡一区| 岛国一区二区在线观看| 99这里只有久久精品视频| 91同城在线观看| 欧美日韩一区小说| 欧美精品亚洲二区| 欧美成人精品福利| 国产婷婷色一区二区三区| 国产精品美女久久久久久| 中文字幕一区二区三区在线播放 | 国产馆精品极品| 国产不卡免费视频| 色哟哟在线观看一区二区三区| 欧洲亚洲国产日韩| 欧美一级专区免费大片| 久久综合九色综合97婷婷女人| 国产亚洲一区二区在线观看| 中文字幕制服丝袜成人av| 亚洲主播在线播放| 国内一区二区视频| 91看片淫黄大片一级在线观看| 日本精品免费观看高清观看| 欧美一区二区三区免费| 久久久综合视频| 亚洲资源中文字幕| 国产精品影音先锋| 91社区在线播放| 精品sm在线观看| 一二三区精品福利视频| 国产麻豆午夜三级精品| 色哟哟日韩精品| 久久久久九九视频| 午夜视频在线观看一区二区| 激情五月激情综合网| 在线免费观看日本欧美| 精品国产91九色蝌蚪| 午夜欧美一区二区三区在线播放| 国产成人午夜99999|