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

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

?? 008.htm

?? 21天內快速掌握c++語言
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>-->Learn C++ in 21 Days-->Day 8</TITLE>
<META NAME="888" CONTENT=" Learn C++ in 21 Days Day 8">
<META NAME="888" CONTENT=" - Learn C++ in 21 Days - Day 8">

<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋體"}
.tt2 {font: 12pt/15pt "宋體"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<p align="center"><script src="../../../1.js"></script> </p>
<TD CLASS="tt3" VALIGN="top" width="8%"  bgcolor="#ffffff"><strong><A HREF="009.htm"><FONT style="FONT-SIZE: 9pt">后一頁</font></A><BR>
<A HREF="007.htm"><FONT style="FONT-SIZE: 9pt">前一頁</font></A><BR>

<A HREF="index.html"><FONT style="FONT-SIZE: 9pt">回目錄</font></A><BR>
 
<TD class="tt2" bgcolor="#ffffff" width="100%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷體_GB2312">Day 8</FONT></B></center>
 
	<LI><A HREF="#Heading1">Day 8</A>
	<UL>
		<LI><A HREF="#Heading2">Pointers</A>
		<UL>
			<LI><A HREF="#Heading3">What Is a Pointer?</A>
			<UL>
				<LI><A HREF="#Heading4">Figure 8.1.</A>
			</UL>
			<LI><A HREF="#Heading5">Listing 8.1. Demonstrating address of variables</A>
			<UL>
				<LI><A HREF="#Heading7">Figure 8.2.</A>
			</UL>
			<LI><A HREF="#Heading8">Storing the Address in a Pointer</A>
			<UL>
				<LI><A HREF="#Heading9">Pointer Names</A>
				<LI><A HREF="#Heading10">The Indirection Operator</A>
				<LI><A HREF="#Heading11">Pointers, Addresses, and Variables</A>
				<UL>
					<LI><A HREF="#Heading12">Figure 8.3.</A>
				</UL>
				<LI><A HREF="#Heading13">Manipulating Data by Using Pointers</A>
			</UL>
			<LI><A HREF="#Heading14">Listing 8.2. Manipulating data by using pointers</A>
			<UL>
				<LI><A HREF="#Heading16">Examining the Address</A>
			</UL>
			<LI><A HREF="#Heading17">Listing 8.3. Finding out what is stored in pointers</A>
			<LI><A HREF="#Heading19">Pointers</A>
			<LI><A HREF="#Heading20">Why Would You Use Pointers?</A>
			<LI><A HREF="#Heading21">The Stack and the Free Store</A>
			<UL>
				<LI><A HREF="#Heading22">new</A>
				<LI><A HREF="#Heading23">delete</A>
			</UL>
			<LI><A HREF="#Heading24">Listing 8.4. Allocating, using, and deleting pointers.</A>
			<LI><A HREF="#Heading25">Memory Leaks</A>
			<LI><A HREF="#Heading26">Creating Objects on the Free Store</A>
			<LI><A HREF="#Heading27">Deleting Objects</A>
			<LI><A HREF="#Heading28">Listing 8.5. Creating and deleting objects on the free store</A>
			<LI><A HREF="#Heading30">Accessing Data Members</A>
			<LI><A HREF="#Heading31">Listing 8.6. Accessing member data of objects</A>
			<LI><A HREF="#Heading32">on the free store.</A>
			<LI><A HREF="#Heading33">Member Data on the Free Store</A>
			<LI><A HREF="#Heading34">Listing 8.7. Pointers as member data</A>
			<LI><A HREF="#Heading36">The this Pointer</A>
			<LI><A HREF="#Heading37">Listing 8.8. Using the this pointer</A>
			<LI><A HREF="#Heading39">Stray or Dangling Pointers</A>
			<LI><A HREF="#Heading40">Listing 8.9. Creating a stray pointer</A>
			<LI><A HREF="#Heading42">const Pointers</A>
			<UL>
				<LI><A HREF="#Heading43">const Pointers and const Member Functions</A>
			</UL>
			<LI><A HREF="#Heading44">Listing 8.10. Using pointers to const objects</A>
			<UL>
				<LI><A HREF="#Heading46">const this Pointers</A>
			</UL>
			<LI><A HREF="#Heading47">Summary</A>
			<LI><A HREF="#Heading48">Q&amp;A</A>
			<LI><A HREF="#Heading49">Workshop</A>
			<UL>
				<LI><A HREF="#Heading50">Quiz</A>
				<LI><A HREF="#Heading51">Exercises</A>
			</UL>
		</UL>
	</UL>
</UL>
<BR>
<P>
<HR SIZE="4">
<BR>
<H2 ALIGN="CENTER"><A NAME="Heading1"></A><FONT COLOR="#000077">Day 8</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">Pointers</FONT></H2>
<P>One of the most powerful tools available to a C++ programmer is the ability to
manipulate computer memory directly by using pointers. Today you will learn
<BR>
<UL>
	<LI>What pointers are.
	<P>
	<LI>How to declare and use pointers.
	<P>
	<LI>What the free store is and how to manipulate memory.
</UL>
<BR>
<P>Pointers present two special challenges when learning C++: They can be somewhat
confusing, and it isn't immediately obvious why they are needed. This chapter explains
how pointers work, step by step. You will fully understand the need for pointers,
however, only as the book progresses.
<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">What Is a Pointer?</FONT></H3>
<BR>
<DL>
	<DD>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>pointer</I> is a variable
	that holds a memory address.
<HR>
<BR>
</DL>
<BR>
<P>To understand pointers, you must know a little about computer memory. Computer
memory is divided into sequentially numbered memory locations. Each variable is located
at a unique location in memory, known as its address. (This is discussed in the &quot;Extra
Credit&quot; section following Day 5, &quot;Functions.&quot;) Figure 8.1 shows a
schematic representation of the storage of an <TT>unsigned long</TT> integer variable
<TT>theAge</TT>.<BR>
<BR>
<A NAME="Heading4"></A><A HREF="figure1.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310708/art/ch08/figure1.jpg"><FONT COLOR="#000077">Figure
8.1.</FONT></A><I> A schematic representation of <TT>theAge</TT></I>.<BR>
<BR>
Different computers number this memory using different, complex schemes. Usually
programmers don't need to know the particular address of any given variable, because
the compiler handles the details. If you want this information, though, you can use
the <TT>address of</TT> operator (<TT>&amp;</TT>), which is illustrated in Listing
8.1.</P>
<P><A NAME="Heading5"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 8.1. Demonstrating
address of variables.</B></FONT></P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">1:   // Listing 8.1 Demonstrates address of operator
2:   // and addresses of local variables
3:
4:   #include &lt;iostream.h&gt;
5:
6:   int main()
7:   {
8:      unsigned short shortVar=5;
9:      unsigned long  longVar=65535;
10:     long sVar = -65535;
11:
12:     cout &lt;&lt; &quot;shortVar:\t&quot; &lt;&lt; shortVar;
13:     cout &lt;&lt; &quot; Address of shortVar:\t&quot;;
14:     cout &lt;&lt;  &amp;shortVar  _&lt;&lt; &quot;\n&quot;;
15:
16:     cout &lt;&lt; &quot;longVar:\t&quot;  &lt;&lt; longVar;
17:      cout  &lt;&lt; &quot; Address of longVar:\t&quot; ;
18:      cout &lt;&lt;  &amp;longVar  _&lt;&lt; &quot;\n&quot;;
19:
20:     cout &lt;&lt; &quot;sVar:\t&quot;     &lt;&lt; sVar;
21:       cout     &lt;&lt; &quot; Address of sVar:\t&quot; ;
22:       cout     &lt;&lt;  &amp;sVar     _&lt;&lt; &quot;\n&quot;;
23:
24:  return 0;
<TT>25: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: shortVar: 5       Address of shortVar: 0x8fc9:fff4
longVar:  65535   Address of longVar:  0x8fc9:fff2
sVar:    -65535   Address of sVar:     0x8fc9:ffee
</FONT></PRE>
<P>(Your printout may look different.)</P>
<P><BR>
<FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>Three variables are declared
and initialized: a <TT>short</TT> in line 8, an <TT>unsigned long</TT> in line 9,
and a <TT>long</TT> in line 10. Their values and addresses are printed in lines 12-16,
by using the <TT>address of</TT> operator (<TT>&amp;</TT>).<BR>
The value of <TT>shortVar</TT> is <TT>5</TT>, as expected, and its address is <TT>0x8fc9:fff4</TT>
when run on my 80386-based computer. This complicated address is computer-specific
and may change slightly each time the program is run. Your results will be different.
What doesn't change, however, is that the difference in the first two addresses is
two bytes if your computer uses two-byte <TT>short</TT> integers. The difference
between the second and third is four bytes if your computer uses four-byte <TT>long</TT>
integers. Figure 8.2 illustrates how the variables in this program would be stored
in memory.<BR>
<BR>
<A NAME="Heading7"></A><A HREF="figure2.jpg" tppabs="http://pbs.mcp.com/ebooks/0672310708/art/ch08/figure2.jpg"><FONT COLOR="#000077">Figure
8.2.</FONT></A><FONT COLOR="#000077"><I> </I></FONT><I>Illustration of variable storage.</I><BR>
<BR>
There is no reason why you need to know the actual numeric value of the address of
each variable. What you care about is that each one has an address and that the right
amount of memory is set aside. You tell the compiler how much memory to allow for
your variables by declaring the variable type; the compiler automatically assigns
an address for it. For example, a <TT>long</TT> integer is typically four bytes,
meaning that the variable has an address to four bytes of memory.
<H4 ALIGN="CENTER"><A NAME="Heading8"></A><FONT COLOR="#000077">Storing the Address
in a Pointer</FONT></H4>
<P>Every variable has an address. Even without knowing the specific address of a
given variable, you can store that address in a pointer.</P>
<P>For example, suppose that <TT>howOld</TT> is an integer. To declare a pointer
called <TT>pAge</TT> to hold its address, you would write</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">int *pAge = 0;
</FONT></PRE>
<P>This declares <TT>pAge</TT> to be a pointer to <TT>int</TT>. That is, <TT>pAge</TT>
is declared to hold the address of an <TT>int</TT>.</P>
<P>Note that <TT>pAge</TT> is a variable like any of the variables. When you declare
an integer variable (type <TT>int</TT>), it is set up to hold an integer. When you
declare a pointer variable like <TT>pAge</TT>, it is set up to hold an address. <TT>pAge</TT>
is just a different type of variable.</P>
<P>In this example, <TT>pAge</TT> is initialized to zero. A pointer whose value is
zero is called a null pointer. All pointers, when they are created, should be initialized
to something. If you don't know what you want to assign to the pointer, assign <TT>0</TT>.
A pointer that is not initialized is called a wild pointer. Wild pointers are very
dangerous.
<BR>
<BR>
<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Practice safe computing: Initialize
	your pointers!
<HR>
<BR>
<BR>
</BLOCKQUOTE>
<BR>
<P>If you do initialize the pointer to <TT>0</TT>, you must specifically assign the
address of <TT>howOld</TT> to <TT>pAge</TT>. Here's an example that shows how to
do that:</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">unsigned short int howOld = 50;     // make a variable
unsigned short int * pAge = 0;      // make a pointer
pAge = &amp;howOld;                     // put howOld's address in pAge
</FONT></PRE>
<P>The first line creates a variable--<TT>howOld</TT>, whose type is <TT>unsigned
short int</TT>--and initializes it with the value <TT>50</TT>. The second line declares
<TT>pAge</TT> to be a pointer to type <TT>unsigned short int</TT> and initializes
it to zero. You know that <TT>pAge</TT> is a pointer because of the asterisk (<TT>*</TT>)
after the variable type and before the variable name.</P>
<P>The third and final line assigns the address of <TT>howOld</TT> to the pointer
<TT>pAge</TT>. You can tell that the address of <TT>howOld</TT> is being assigned
because of the <TT>address of</TT> operator (<TT>&amp;</TT>). If the <TT>address
of</TT> operator had not been used, the value of <TT>howOld</TT> would have been
assigned. That might, or might not, have been a valid address.</P>
<P>At this point, <TT>pAge</TT> has as its value the address of <TT>howOld</TT>.
<TT>howOld</TT>, in turn, has the value <TT>50</TT>. You could have accomplished
this with one less step, as in</P>
<PRE><FONT COLOR="#0066FF" font style="font-size:10pt">unsigned short int howOld = 50;       // make a variable
unsigned short int * pAge = &amp;howOld;  // make pointer to howOld
</FONT></PRE>
<P><TT>pAge</TT> is a pointer that now contains the address of the <TT>howOld</TT>
variable. Using <TT>pAge</TT>, you can actually determine the value of <TT>howOld</TT>,
which in this case is <TT>50</TT>. Accessing <TT>howOld</TT> by using the pointer
<TT>pAge</TT> is called indirection because you are indirectly accessing <TT>howOld</TT>
by means of<TT> pAge</TT>. Later today you will see how to use indirection to access
a variable's value.</P>
<BR>
<DL>
	<DD>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>Indirection means accessing
	the value at the address held by a pointer. The pointer provides an indirect way
	to get the value held at that address.
<HR>
<BR>
</DL>
<BR>
<H4 ALIGN="CENTER"><A NAME="Heading9"></A><FONT COLOR="#000077">Pointer Names</FONT></H4>
<P>Pointers can have any name that is legal for other variables. This book follows
the convention of naming all pointers with an initial <TT>p</TT>, as in <TT>pAge</TT>
or <TT>pNumber</TT>.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩国产片| 美腿丝袜亚洲色图| 91免费版在线| 亚洲欧美电影一区二区| 成人少妇影院yyyy| 久久久久久影视| 久久成人免费网| 欧美一区二区播放| 美国精品在线观看| 精品sm捆绑视频| 国产美女视频91| 国产女同性恋一区二区| 成人sese在线| 日韩伦理电影网| 91高清在线观看| 亚洲成人综合在线| 欧美一区二区私人影院日本| 亚洲国产成人91porn| 欧美午夜精品久久久久久孕妇 | 精品一区二区三区在线观看国产| 91麻豆精品国产91久久久资源速度 | 亚洲一区二区三区在线看| 91久久精品网| 日韩av电影一区| 欧美成人video| 福利视频网站一区二区三区| 中文字幕一区二区三区在线观看 | 最新不卡av在线| 精品1区2区3区| 男人的j进女人的j一区| 亚洲精品一区二区在线观看| 成人18精品视频| 一区二区成人在线观看| 日韩一区二区三区电影在线观看 | 欧美日韩精品三区| 久久国产精品无码网站| 国产精品久久久久久妇女6080 | 天天综合色天天综合| 精品日韩av一区二区| 成人app网站| 五月天网站亚洲| 国产视频一区二区在线| 色噜噜偷拍精品综合在线| 视频一区二区三区入口| 精品国产免费一区二区三区香蕉| 国产不卡在线播放| 五月婷婷欧美视频| 国产精品美女久久久久久| 欧美亚洲高清一区| 国产精品一区二区三区99| 国产视频一区在线观看| 欧美三级电影网站| 亚洲一区在线观看视频| 欧美一激情一区二区三区| 国产寡妇亲子伦一区二区| 亚洲国产日产av| 久久久国产精品不卡| 一本色道久久综合亚洲91| 久久国产剧场电影| 亚洲成av人片在线观看| 国产欧美日韩视频一区二区| 91精品蜜臀在线一区尤物| 成a人片亚洲日本久久| 麻豆freexxxx性91精品| 亚洲综合一二三区| 国产精品久久午夜夜伦鲁鲁| 日韩久久精品一区| 欧美视频完全免费看| www.亚洲人| 国模冰冰炮一区二区| 五月天激情综合网| 一区二区久久久| 国产精品欧美综合在线| 欧美精品国产精品| 在线观看日韩毛片| 不卡欧美aaaaa| 国产呦萝稀缺另类资源| 日韩av在线发布| 亚洲精品老司机| 国产精品国产三级国产专播品爱网| 欧美一级一区二区| 欧美三级三级三级爽爽爽| 99re热这里只有精品视频| 国产成a人亚洲| 国产一区不卡在线| 国产精品一区一区| 国产一区二区三区国产| 日韩精品国产欧美| 欧美aa在线视频| 日本成人超碰在线观看| 偷偷要91色婷婷| 亚洲va韩国va欧美va| 中文字幕中文字幕一区| 久久久久久久久久久99999| 中文字幕av一区二区三区| 亚洲欧美在线视频| 亚洲国产精品久久一线不卡| 日韩国产欧美在线视频| 韩国精品主播一区二区在线观看| 国产电影一区二区三区| 色老综合老女人久久久| 欧美一卡二卡在线观看| 国产日韩成人精品| 亚洲一区二区精品3399| 久久成人精品无人区| 成人免费高清视频| 在线电影欧美成精品| 国产亚洲一区字幕| 亚洲午夜视频在线观看| 精品一区二区三区av| 91免费视频观看| 日韩丝袜美女视频| 亚洲视频一区在线| 精品一区二区三区在线观看| 91影视在线播放| 日韩精品一区二区三区在线观看| 国产精品乱人伦中文| 人人精品人人爱| 99久久er热在这里只有精品66| 欧美色男人天堂| 欧美激情在线免费观看| 午夜视频一区在线观看| 成人黄色在线看| 日韩欧美国产高清| 亚洲曰韩产成在线| 成人午夜视频在线| 欧美一区二区美女| 一区二区三区四区高清精品免费观看| 卡一卡二国产精品| 欧美三级视频在线播放| 中文字幕av在线一区二区三区| 视频一区欧美精品| 在线欧美日韩精品| 欧美激情在线免费观看| 蜜桃视频一区二区三区| 在线观看不卡视频| 综合久久久久综合| 国产精品一区二区你懂的| 欧美一级欧美三级| 亚洲国产日日夜夜| 色av综合在线| 中文字幕一区日韩精品欧美| 国产一区二区导航在线播放| 9191国产精品| 午夜欧美一区二区三区在线播放| 91麻豆高清视频| 国产精品美女久久久久久久| 国产一区亚洲一区| 欧美v国产在线一区二区三区| 亚欧色一区w666天堂| 欧美影院一区二区| 亚洲免费在线播放| 91视频一区二区| 日韩理论在线观看| 91在线你懂得| 亚洲女厕所小便bbb| 成人国产亚洲欧美成人综合网| 久久亚洲春色中文字幕久久久| 日韩av电影天堂| 欧美一级艳片视频免费观看| 日韩精品1区2区3区| 91.麻豆视频| 免费观看成人av| 精品久久一二三区| 黑人巨大精品欧美黑白配亚洲| 欧美一区二区三区视频在线观看| 天天综合天天做天天综合| 欧美日韩免费在线视频| 亚洲高清视频在线| 日韩一二在线观看| 国产一区二区在线观看免费| 精品国精品自拍自在线| 国产一区在线不卡| 国产精品色一区二区三区| 成人少妇影院yyyy| 亚洲精品日韩综合观看成人91| 日本高清视频一区二区| 亚洲高清一区二区三区| 正在播放亚洲一区| 精品一区精品二区高清| 欧美国产一区在线| 不卡的电视剧免费网站有什么| 中文字幕一区二区三| 欧美亚洲综合在线| 麻豆国产精品一区二区三区| 亚洲精品一区二区三区精华液| 国产在线精品免费| 亚洲天堂久久久久久久| 欧美日韩免费电影| 久久99精品一区二区三区三区| 久久久久久久精| 一本大道久久精品懂色aⅴ| 亚洲电影欧美电影有声小说| 91精品久久久久久蜜臀| 国产a视频精品免费观看| 一区二区激情小说| 久久综合九色综合97_久久久| 99精品久久99久久久久| 午夜精品免费在线观看| 久久久久97国产精华液好用吗|