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

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

?? ch08.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="ch07rv1.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch07rv1.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="ch09.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch09.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 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>

<P>
<HR SIZE="4">

<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

<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>

<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>

<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>

</DL>

<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="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch08/figure1.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/ch08/figure1.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/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">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="javascript:if(confirm('http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/art/ch08/figure2.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/ch08/figure2.jpg'" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/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">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.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Practice safe computing: Initialize
	your pointers! 
<HR>


</BLOCKQUOTE>

<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">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">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>

<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>

</DL>

<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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91在线视频免费91| 亚洲成a人v欧美综合天堂| 韩国女主播成人在线| 91麻豆精品国产91久久久更新时间| 亚洲视频一区二区在线| 色综合一个色综合亚洲| 亚洲欧洲中文日韩久久av乱码| 91免费精品国自产拍在线不卡| 亚洲欧美激情在线| 欧美偷拍一区二区| 天天射综合影视| 精品国产区一区| 成人爽a毛片一区二区免费| 亚洲人成小说网站色在线| 欧美精品粉嫩高潮一区二区| 国产真实乱子伦精品视频| 亚洲人123区| 日韩三级高清在线| 成人av综合在线| 亚洲午夜免费视频| 日韩欧美久久一区| 成人av在线资源网站| 亚洲最新在线观看| 日韩一区二区三区在线| 国产成人欧美日韩在线电影| 一区二区三区影院| 91精品国产91热久久久做人人| 国产成人在线视频网址| 亚洲福利视频三区| 日本一区二区三区国色天香| 欧美自拍偷拍一区| 国产精品一品二品| 一区二区三区在线观看视频| 精品蜜桃在线看| 97成人超碰视| 国产一二三精品| 午夜成人免费电影| 国产精品大尺度| 欧美videossexotv100| 91麻豆成人久久精品二区三区| 日本v片在线高清不卡在线观看| 中文字幕成人网| 欧美成人猛片aaaaaaa| 欧洲在线/亚洲| 成人黄色av电影| 国产一区二区不卡老阿姨| 天堂va蜜桃一区二区三区| 国产精品国产三级国产aⅴ原创| 欧美一区二区三区思思人| 欧美亚洲综合另类| 91视频在线观看免费| 国产精品888| 久久99在线观看| 亚洲成a人片在线不卡一二三区| 国产精品白丝在线| 337p日本欧洲亚洲大胆精品| 欧美日韩aaaaaa| 色欧美日韩亚洲| 本田岬高潮一区二区三区| 免费av网站大全久久| 亚洲综合激情网| 亚洲欧洲成人自拍| 国产精品乱人伦| 国产午夜一区二区三区| 欧美精品一区二区三区一线天视频| 欧美午夜精品久久久久久孕妇| 成人免费观看视频| 国产精品18久久久久久久久久久久| 免费观看在线综合| 日韩高清在线电影| 午夜精品123| 亚洲成人自拍偷拍| 亚洲欧美偷拍另类a∨色屁股| 欧美国产日韩精品免费观看| xf在线a精品一区二区视频网站| 日韩午夜电影av| 精品福利视频一区二区三区| 精品国产欧美一区二区| 欧美精品一区二区久久久| 日韩欧美自拍偷拍| 日韩欧美第一区| 精品美女被调教视频大全网站| 欧美二区三区91| 日韩午夜精品电影| 久久综合999| 国产午夜精品一区二区三区四区| 国产色产综合产在线视频| 欧美一级黄色片| 精品国产制服丝袜高跟| 日韩久久精品一区| 国产亚洲美州欧州综合国| 国产精品人成在线观看免费| 亚洲欧美日韩一区二区三区在线观看| 亚洲免费毛片网站| 亚洲图片欧美综合| 麻豆国产精品一区二区三区 | 欧美在线啊v一区| 91国模大尺度私拍在线视频| 在线区一区二视频| 欧美一区二区啪啪| 欧美精品一区二区三区蜜桃视频| 欧美不卡视频一区| 中文无字幕一区二区三区| 18成人在线视频| 亚洲国产sm捆绑调教视频 | 欧洲中文字幕精品| 日韩一级视频免费观看在线| 中文字幕精品三区| 亚洲成av人片一区二区梦乃| 黑人精品欧美一区二区蜜桃| 国产sm精品调教视频网站| 91日韩精品一区| 欧美一级日韩免费不卡| 国产日韩视频一区二区三区| 亚洲美女少妇撒尿| 久久综合综合久久综合| 成人做爰69片免费看网站| 在线观看免费视频综合| 精品久久久久久久久久久久包黑料 | 色噜噜久久综合| 日韩欧美一级二级| 亚洲色图欧美激情| 精品亚洲成a人在线观看| 99久久精品免费看国产| 日韩欧美一区在线观看| 亚洲黄色免费网站| 国产一区二区伦理| 欧美日韩国产成人在线免费| 国产香蕉久久精品综合网| 亚洲一区二区在线观看视频| 国产精品一品二品| 欧美一区二区成人6969| 夜夜嗨av一区二区三区中文字幕| 福利电影一区二区| 欧美tk—视频vk| 五月婷婷综合网| 91浏览器在线视频| 国产亚洲欧美一级| 久久99精品国产91久久来源| 欧美性感一类影片在线播放| 中文字幕欧美三区| 国产一区 二区 三区一级| 欧美精品亚洲二区| 亚洲国产综合视频在线观看| 成人免费高清在线观看| 久久亚洲免费视频| 美女国产一区二区三区| 91精品婷婷国产综合久久竹菊| 中文字幕日韩精品一区| 成人国产一区二区三区精品| 国产亚洲一区二区三区在线观看| 毛片av一区二区| 日韩亚洲欧美中文三级| 青青草视频一区| 欧美美女激情18p| 五月天亚洲精品| 欧美精选午夜久久久乱码6080| 亚洲高清一区二区三区| 91传媒视频在线播放| 一区二区免费在线| 欧美日韩日日骚| 亚洲成人av免费| 欧美日韩国产小视频在线观看| 亚洲亚洲精品在线观看| 91精品福利视频| 亚洲国产一区二区视频| 在线精品视频免费观看| 亚洲国产一区视频| 欧美精品粉嫩高潮一区二区| 男男视频亚洲欧美| 日韩一区二区三区av| 久久草av在线| 国产欧美日本一区视频| 成人高清免费在线播放| 亚洲女厕所小便bbb| 日本福利一区二区| 肉肉av福利一精品导航| 日韩精品一区二区三区swag| 国产乱码精品一区二区三| 中文字幕欧美三区| 欧美综合一区二区| 奇米色一区二区| 国产人成亚洲第一网站在线播放| 成人一级视频在线观看| 亚洲欧美一区二区三区国产精品 | 亚洲欧洲精品成人久久奇米网| 97久久精品人人做人人爽50路| 亚洲一线二线三线视频| 51久久夜色精品国产麻豆| 寂寞少妇一区二区三区| 中文字幕av一区二区三区| 欧洲国产伦久久久久久久| 日本欧美大码aⅴ在线播放| 久久久久久久国产精品影院| 91亚洲大成网污www| 天堂va蜜桃一区二区三区漫画版 | 91看片淫黄大片一级在线观看| 亚洲综合一二区| 久久综合资源网| 91猫先生在线|