page593.html
来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 58 行
HTML
58 行
<HTML>
<HEAD>
<TITLE>Pass By Reference</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html9232" HREF="page594.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page594.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html9230" HREF="page591.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page591.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html9226" HREF="page592.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page592.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html9234" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html9235" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H2><A NAME="SECTION0018220000000000000000">Pass By Reference</A></H2>
<P>
Consider the pair of C++ functions defined in Program <A HREF="page593.html#progcpp2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page593.html#progcpp2c"><IMG ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
The only difference between this code and the code given in Program <A HREF="page592.html#progcpp1c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page592.html#progcpp1c"><IMG ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>
is the definition of the formal parameter of the function <tt>Two</tt>:
In this case,
the parameter <tt>x</tt> is declared to be a <em>reference</em> to an <tt>int</tt>.
In general, if the type of a formal parameter is a reference,
then the parameter passing method is
<em>pass-by-reference</em><A NAME=57184> </A>.
<P>
<P><A NAME="57188"> </A><A NAME="progcpp2c"> </A> <IMG WIDTH=575 HEIGHT=238 ALIGN=BOTTOM ALT="program57185" SRC="img2600.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img2600.gif" ><BR>
<STRONG>Program:</STRONG> Example of Pass-By-Reference Parameter Passing<BR>
<P>
<P>
A reference formal parameter is not a variable.
When a function is called that has a reference formal parameter,
the effect of the call is to associate the reference with
the corresponding actual parameter.
I.e., the reference becomes
an alternative name for the corresponding actual parameter.
Consequently, this means that the actual parameter passed by reference
must be variable.
<P>
A reference formal parameter can be used in the
called function everywhere that a variable can be used.
In particular, if the reference formal parameter is used
where a <I>r</I>-value is required,
it is the <I>r</I>-value of actual parameter that is obtained.
Similarly, if the reference parameter is used where an <I>l</I>-value is required,
it is the <I>l</I>-value of actual parameter that is obtained.
Therefore, the output obtained produced by the function <tt>One</tt>
defined in Program <A HREF="page593.html#progcpp2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page593.html#progcpp2c"><IMG ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> is:
<PRE>2
2</PRE>
<P>
<BR> <HR>
<UL>
<LI> <A NAME="tex2html9236" HREF="page594.html#SECTION0018221000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page594.html#SECTION0018221000000000000000">The Trade-off</A>
<LI> <A NAME="tex2html9237" HREF="page595.html#SECTION0018222000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page595.html#SECTION0018222000000000000000">Constant Parameters</A>
</UL>
<HR><A NAME="tex2html9232" HREF="page594.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page594.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html9230" HREF="page591.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page591.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html9226" HREF="page592.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page592.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html9234" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html9235" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html \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://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright © 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html \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://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?