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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch11.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->

	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
	<TITLE>Teach Yourself C++ in 21 Days</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<H1 ALIGN="CENTER"><A HREF="ch10.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch10.htm"><IMG SRC="../buttons/BLANPREV.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANPREV.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="javascript:if(confirm('http://www.mcp.com/sams  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mcp.com/sams'" tppabs="http://www.mcp.com/sams"><IMG
SRC="../buttons/BLANHOME.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANHOME.GIF" WIDTH="37" HEIGHT="37" ALIGN="BOTTOM"
BORDER="0"></A><A HREF="../index.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/index.htm"><IMG SRC="../buttons/BLANTOC.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANTOC.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="ch12.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch12.htm"><IMG SRC="../buttons/BLANNEXT.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANNEXT.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A></H1>
<H1></H1>

<UL>
	<LI><A HREF="#Heading1">Day 11</A>
	<UL>
		<LI><A HREF="#Heading2">Arrays</A>
		<UL>
			<LI><A HREF="#Heading3">What Is an Array?</A>
			<UL>
				<LI><A HREF="#Heading4">Figure 11.1.</A>
			</UL>
			<LI><A HREF="#Heading5">Array Elements</A>
			<LI><A HREF="#Heading6">Listing 11.1. Using an integer array</A><A HREF="#Heading7">.</A>
			<LI><A HREF="#Heading8">Writing Past the End of an Array</A>
			<LI><A HREF="#Heading9">Listing 11.2. Writing past the end of an array</A><A HREF="#Heading10">.</A>
			<LI><A HREF="#Heading11">Fence Post Errors</A>
			<UL>
				<LI><A HREF="#Heading12">Figure 11.2.</A>
			</UL>
			<LI><A HREF="#Heading13">Initializing Arrays</A>
			<LI><A HREF="#Heading14">Declaring Arrays</A>
			<LI><A HREF="#Heading15">Listing 11.3. Using consts and enums in arrays</A><A HREF="#Heading16">.</A>
			<LI><A HREF="#Heading17">Arrays</A>
			<LI><A HREF="#Heading18">Arrays of Objects</A>
			<LI><A HREF="#Heading19">Listing 11.4. Creating an array of objects</A><A HREF="#Heading20">.</A>
			<LI><A HREF="#Heading21">Multidimensional Arrays</A>
			<UL>
				<LI><A HREF="#Heading22">Figure 11.3.</A>
			</UL>
			<LI><A HREF="#Heading23">Initializing Multidimensional Arrays</A>
			<LI><A HREF="#Heading24">Listing 11.5. Creating a multidimensional array</A><A HREF="#Heading25">.</A>
			<UL>
				<LI><A HREF="#Heading26">Figure 11.4.</A>
			</UL>
			<LI><A HREF="#Heading27">A Word About Memory</A>
			<LI><A HREF="#Heading28">Arrays of Pointers</A>
			<LI><A HREF="#Heading29">Listing 11.6. Storing an array on the free store</A><A HREF="#Heading30">.</A>
			<LI><A HREF="#Heading31">Declaring Arrays on the Free Store</A>
			<LI><A HREF="#Heading32">A Pointer to an Array Versus an Array of Pointers</A>
			<LI><A HREF="#Heading33">Pointers and Array Names</A>
			<LI><A HREF="#Heading34">Listing 11.7. Creating an array by using new</A><A HREF="#Heading35">.</A>
			<LI><A HREF="#Heading36">Deleting Arrays on the Free Store</A>
			<LI><A HREF="#Heading37">char Arrays</A>
			<LI><A HREF="#Heading38">Listing 11.8. Filling an array</A><A HREF="#Heading39">.</A>
			<LI><A HREF="#Heading40">Listing 11.9. Filling an array.</A>
			<LI><A HREF="#Heading41">strcpy() and strncpy()</A>
			<LI><A HREF="#Heading42">Listing 11.10. Using strcpy().</A>
			<LI><A HREF="#Heading43">Listing 11.11. Using strncpy().</A>
			<LI><A HREF="#Heading44">String Classes</A>
			<LI><A HREF="#Heading45">Listing 11.12. Using a String class</A><A HREF="#Heading46">.</A>
			<LI><A HREF="#Heading47">Linked Lists and Other Structures</A>
			<UL>
				<LI><A HREF="#Heading48">Figure 11.5.</A>
			</UL>
			<LI><A HREF="#Heading49">Listing 11.13. Implementing a linked list</A><A HREF="#Heading50">.</A>
			<UL>
				<LI><A HREF="#Heading51">Figure 11.6.</A>
			</UL>
			<LI><A HREF="#Heading52">Array Classes</A>
			<LI><A HREF="#Heading53">Summary</A>
			<LI><A HREF="#Heading54">Q&amp;A</A>
			<LI><A HREF="#Heading55">Workshop</A>
			<UL>
				<LI><A HREF="#Heading56">Quiz</A>
				<LI><A HREF="#Heading57">Exercises</A>
			</UL>
		</UL>
	</UL>
</UL>

<P>
<HR SIZE="4">

<H2 ALIGN="CENTER"><A NAME="Heading1"></A><FONT COLOR="#000077">Day 11</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">Arrays</FONT></H2>
<P>In previous chapters, you declared a single <TT>int</TT>, <TT>char</TT>, or other
object. You often want to declare a collection of objects, such as 20 <TT>int</TT>s
or a litter of <TT>CAT</TT>s. Today, you learn

<UL>
	<LI>What arrays are and how to declare them.
	<P>
	<LI>What strings are and how to use character arrays to make them.
	<P>
	<LI>The relationship between arrays and pointers.
	<P>
	<LI>How to use pointer arithmetic with arrays.
</UL>

<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">What Is an Array?</FONT></H3>
<P>An array is a collection of data storage locations, each of which holds the same
type of data. Each storage location is called an element of the array.</P>
<P>You declare an array by writing the type, followed by the array name and the subscript.
The subscript is the number of elements in the array, surrounded by square brackets.
For example,</P>
<PRE><FONT COLOR="#0066FF">long LongArray[25];
</FONT></PRE>
<P>declares an array of 25 <TT>long</TT> integers, named <TT>LongArray</TT>. When
the compiler sees this declaration, it sets aside enough memory to hold all 25 elements.
Because each <TT>long</TT> integer requires 4 bytes, this declaration sets aside
100 contiguous bytes of memory, as illustrated in Figure 11.1.<BR>
<BR>
<A NAME="Heading4"></A><A HREF="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp01.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/11zcp01.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch11/11zcp01.jpg"><FONT COLOR="#000077">Figure
11.1.</FONT></A><FONT COLOR="#000077"><I> </I></FONT><I>Declaring an array.</I>
<H3 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">Array Elements</FONT></H3>
<P>You access each of the array elements by referring to an offset from the array
name. Array elements are counted from zero. Therefore, the first array element is
<TT>arrayName[0]</TT>. In the <TT>LongArray</TT> example, <TT>LongArray[0]</TT> is
the first array element, <TT>LongArray[1]</TT> the second, and so forth.</P>
<P>This can be somewhat confusing. The array <TT>SomeArray[3]</TT> has three elements.
They are <TT>SomeArray[0]</TT>, <TT>SomeArray[1]</TT>, and <TT>SomeArray[2]</TT>.
More generally, <TT>SomeArray[n]</TT> has n elements that are numbered <TT>SomeArray[0]</TT>
through <TT>SomeArray[n-1]</TT>.</P>
<P>Therefore, <TT>LongArray[25]</TT> is numbered from <TT>LongArray[0]</TT> through
<TT>LongArray[24]</TT>. Listing 11.1 shows how to declare an array of five integers
and fill each with a value.</P>
<P><A NAME="Heading6"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 11.1. Using an
integer array.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">
1:     //Listing 11.1 - Arrays
2:     #include &lt;iostream.h&gt;
3:
4:     int main()
5:     {
6:        int myArray[5];
7:        int i;
8:        for ( i=0; i&lt;5; i++)  // 0-4
9:        {
10:           cout &lt;&lt; &quot;Value for myArray[&quot; &lt;&lt; i &lt;&lt; &quot;]: &quot;;
11:          cin &gt;&gt; myArray[i];
12:       }
13:       for (i = 0; i&lt;5; i++)
14:          cout &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; myArray[i] &lt;&lt; &quot;\n&quot;;
15:     return 0;
<TT>16: }</TT>
Output: Value for myArray[0]:  3
Value for myArray[1]:  6
Value for myArray[2]:  9
Value for myArray[3]:  12
Value for myArray[4]:  15
0: 3
1: 6
2: 9
3: 12
4: 15
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>Line 6 declares an array
called <TT>myArray</TT>, which holds five integer variables. Line 8 establishes a
loop that counts from 0 through 4, which is the proper set of offsets for a five-element
array. The user is prompted for a value, and that value is saved at the correct offset
into the array.<BR>
<BR>
The first value is saved at <TT>myArray[0]</TT>, the second at <TT>myArray[1]</TT>,
and so forth. The second <TT>for</TT> loop prints each value to the screen.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Arrays count from 0, not from 1.
	This is the cause of many bugs in programs written by C++ novices. Whenever you use
	an array, remember that an array with 10 elements counts from <TT>ArrayName[0]</TT>
	to <TT>ArrayName[9]</TT>. There is no <TT>ArrayName[10]</TT>. 
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading8"></A><FONT COLOR="#000077">Writing Past the
End of an Array</FONT></H3>
<P>When you write a value to an element in an array, the compiler computes where
to store the value based on the size of each element and the subscript. Suppose that
you ask to write over the value at <TT>LongArray[5]</TT>, which is the sixth element.
The compiler multiplies the offset (5) by the size of each element--in this case,
4. It then moves that many bytes (20) from the beginning of the array and writes
the new value at that location.</P>
<P>If you ask to write at <TT>LongArray[50]</TT>, the compiler ignores the fact that
there is no such element. It computes how far past the first element it should look
(200 bytes) and then writes over whatever is at that location. This can be virtually
any data, and writing your new value there might have unpredictable results. If you're
lucky, your program will crash immediately. If you're unlucky, you'll get strange
results much later in your program, and you'll have a difficult time figuring out
what went wrong.</P>
<P>The compiler is like a blind man pacing off the distance from a house. He starts
out at the first house, <TT>MainStreet[0]</TT>. When you ask him to go to the sixth
house on Main Street, he says to himself, &quot;I must go five more houses. Each
house is four big paces. I must go an additional 20 steps.&quot; If you ask him to
go to <TT>MainStreet[100]</TT>, and Main Street is only 25 houses long, he will pace
off 400 steps. Long before he gets there, he will, no doubt, step in front of a moving
bus. So be careful where you send him.</P>
<P>Listing 11.2 shows what happens when you write past the end of an array.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>WARNING:</B></FONT><B> </B>Do not run this program; it may
	crash your system! 
<HR>


</BLOCKQUOTE>

<P><A NAME="Heading9"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 11.2. Writing
past the end of an array.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">
1:     //Listing 11.2
2:     // Demonstrates what happens when you write past the end
3:     // of an array
4:
5:     #include &lt;iostream.h&gt;
6:     int main()
7:     {
8:        // sentinels
9:        long sentinelOne[3];
10:       long TargetArray[25]; // array to fill
11:       long sentinelTwo[3];
12:       int i;
13:       for (i=0; i&lt;3; i++)
14:          sentinelOne[i] = sentinelTwo[i] = 0;
15:
16:       for (i=0; i&lt;25; i++)
17:          TargetArray[i] = 0;
18:
19:       cout &lt;&lt; &quot;Test 1: \n&quot;;  // test current values (should be 0)
20:       cout &lt;&lt; &quot;TargetArray[0]: &quot; &lt;&lt; TargetArray[0] &lt;&lt; &quot;\n&quot;;
21:       cout &lt;&lt; &quot;TargetArray[24]: &quot; &lt;&lt; TargetArray[24] &lt;&lt; &quot;\n\n&quot;;
22:
23:       for (i = 0; i&lt;3; i++)
24:       {
25:          cout &lt;&lt; &quot;sentinelOne[&quot; &lt;&lt; i &lt;&lt; &quot;]: &quot;;
26:          cout &lt;&lt; sentinelOne[i] &lt;&lt; &quot;\n&quot;;
27:          cout &lt;&lt; &quot;sentinelTwo[&quot; &lt;&lt; i &lt;&lt; &quot;]: &quot;;
28:           cout &lt;&lt; sentinelTwo[i]&lt;&lt; &quot;\n&quot;;
29:       }
30:
31:       cout &lt;&lt; &quot;\nAssigning...&quot;;
32:       for (i = 0; i&lt;=25; i++)
33:          TargetArray[i] = 20;
34:
35:       cout &lt;&lt; &quot;\nTest 2: \n&quot;;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产曰批免费观看久久久| 亚洲综合一二三区| 国产精品自在欧美一区| 26uuu国产一区二区三区| 国产原创一区二区| 国产精品二三区| 欧美中文字幕一区| 免费在线成人网| 久久精品亚洲一区二区三区浴池| 国产91精品在线观看| 欧美经典一区二区| 在线视频一区二区三| 三级不卡在线观看| 国产欧美视频一区二区三区| 99免费精品视频| 偷拍一区二区三区四区| 日韩视频在线你懂得| 床上的激情91.| 亚洲一区成人在线| 精品99一区二区三区| 一本色道综合亚洲| 老汉av免费一区二区三区| 国产精品人成在线观看免费| 欧美另类久久久品| 国产精品亚洲专一区二区三区| 亚洲男人天堂av| 日韩欧美视频在线| 色综合天天在线| 久久99国内精品| 一区二区三区**美女毛片| 精品国产91洋老外米糕| 一本色道久久加勒比精品| 精品午夜久久福利影院| 亚洲黄色免费电影| 国产肉丝袜一区二区| 在线成人av影院| 99久久99久久精品国产片果冻| 蜜桃视频在线一区| 一区二区三区.www| 国产精品水嫩水嫩| 欧美一区二区啪啪| 在线一区二区视频| 成人网男人的天堂| 久久精品国产精品亚洲综合| 一区二区三区四区在线免费观看 | 欧美福利视频一区| av激情综合网| 激情久久五月天| 夜夜精品视频一区二区| 国产精品久久午夜| 欧美www视频| 91精品国产综合久久精品| 成人av在线资源网站| 国产福利一区二区三区视频在线| 首页国产丝袜综合| 亚洲国产精品久久人人爱| 国产精品国产自产拍高清av王其| 久久久久一区二区三区四区| 日韩亚洲欧美一区二区三区| 欧美视频精品在线| 色激情天天射综合网| 99国产精品国产精品毛片| 成人av免费在线| 国产sm精品调教视频网站| 激情另类小说区图片区视频区| 人人超碰91尤物精品国产| 日韩av在线发布| 免费成人美女在线观看| 青青草国产精品97视觉盛宴| 香蕉加勒比综合久久| 午夜视频一区二区三区| 性做久久久久久久免费看| 一区二区激情视频| 亚洲一区二区三区四区在线观看| 亚洲激情网站免费观看| 亚洲美女淫视频| 亚洲综合av网| 日本亚洲视频在线| 经典一区二区三区| 国产一区二区女| 成人av网站在线| 91免费视频大全| 欧美日韩高清一区二区| 67194成人在线观看| 日韩亚洲欧美在线观看| 久久中文娱乐网| 国产精品伦理一区二区| 亚洲欧美电影一区二区| 婷婷综合在线观看| 久久99精品久久久久久动态图| 国产美女精品人人做人人爽| 成人伦理片在线| 色婷婷综合久久久中文一区二区| 欧美影院一区二区三区| 宅男在线国产精品| 久久综合精品国产一区二区三区| 国产亲近乱来精品视频| 亚洲精品视频观看| 日韩在线播放一区二区| 国产精品一二三四| 91麻豆精品一区二区三区| 9191国产精品| 精品久久国产字幕高潮| 中文字幕亚洲区| 日韩和欧美一区二区| 成人免费视频视频在线观看免费 | 国产二区国产一区在线观看| 91同城在线观看| 欧美一级爆毛片| 国产精品乱码一区二三区小蝌蚪| 亚洲一本大道在线| 狠狠色综合播放一区二区| 日韩你懂的在线播放| 亚洲婷婷综合色高清在线| 日韩高清不卡在线| 成人精品亚洲人成在线| 欧美日韩国产经典色站一区二区三区 | 欧美日韩成人激情| 久久久久97国产精华液好用吗| 成人欧美一区二区三区白人| 午夜欧美电影在线观看| 成人综合婷婷国产精品久久蜜臀 | 久久国产欧美日韩精品| 色综合久久久久| 久久影院午夜论| 日韩精品电影在线观看| 不卡视频在线观看| 精品国产sm最大网站| 香蕉乱码成人久久天堂爱免费| 成人免费va视频| 久久久噜噜噜久噜久久综合| 五月天精品一区二区三区| 99在线精品观看| 国产亚洲人成网站| 老司机免费视频一区二区| 欧美日韩免费一区二区三区 | www.激情成人| 久久久国产精品不卡| 午夜激情久久久| 色天使色偷偷av一区二区| 久久久久久影视| 久久99国产精品尤物| 欧美精品v国产精品v日韩精品| 1区2区3区国产精品| 国产成人免费xxxxxxxx| 久久亚洲二区三区| 免费成人在线网站| 7777精品伊人久久久大香线蕉完整版 | 欧美一级片免费看| 亚洲午夜久久久久久久久久久 | 亚洲成人福利片| 91蝌蚪porny九色| 亚洲色图另类专区| 北条麻妃一区二区三区| 中文字幕欧美日本乱码一线二线| 国产一区二区在线观看免费| 欧美成人精品福利| 麻豆精品一区二区av白丝在线| 欧美丰满一区二区免费视频| 亚洲一区二区三区四区在线| 91成人在线精品| 亚洲综合一二三区| 欧美日韩成人在线一区| 婷婷综合在线观看| 6080yy午夜一二三区久久| 视频一区视频二区中文字幕| 欧美久久一二区| 蜜臀精品久久久久久蜜臀| 91.com在线观看| 久久精品99久久久| 欧美精品一区二区三区久久久| 国产一区久久久| 欧美国产一区在线| 91色|porny| 午夜精品久久久久久久99水蜜桃 | 激情国产一区二区| 久久婷婷国产综合国色天香| 国产一区在线精品| 欧美国产日韩在线观看| 91同城在线观看| 午夜精品免费在线| 91精品国产日韩91久久久久久| 久久99这里只有精品| 国产视频在线观看一区二区三区| 成人激情文学综合网| 一区二区三区四区av| 日韩无一区二区| 高清成人免费视频| 亚洲啪啪综合av一区二区三区| 欧美三区在线观看| 黄色小说综合网站| 成人欧美一区二区三区1314| 欧美精品18+| 国产黄色91视频| 一区二区三区在线观看国产| 91精品国产色综合久久| youjizz久久| 奇米亚洲午夜久久精品| 日本一区二区视频在线观看| 欧美日韩亚洲综合在线 欧美亚洲特黄一级|