<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://assela.pathirana.net/index.php?action=history&amp;feed=atom&amp;title=Template%3ACpptutorial_Pointers</id>
	<title>Template:Cpptutorial Pointers - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://assela.pathirana.net/index.php?action=history&amp;feed=atom&amp;title=Template%3ACpptutorial_Pointers"/>
	<link rel="alternate" type="text/html" href="https://assela.pathirana.net/index.php?title=Template:Cpptutorial_Pointers&amp;action=history"/>
	<updated>2026-05-13T15:47:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.0</generator>
	<entry>
		<id>https://assela.pathirana.net/index.php?title=Template:Cpptutorial_Pointers&amp;diff=3592&amp;oldid=prev</id>
		<title>Root: 1 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://assela.pathirana.net/index.php?title=Template:Cpptutorial_Pointers&amp;diff=3592&amp;oldid=prev"/>
		<updated>2007-06-08T15:04:45Z</updated>

		<summary type="html">&lt;p&gt;1 revision(s)&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:04, 8 June 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Root</name></author>
	</entry>
	<entry>
		<id>https://assela.pathirana.net/index.php?title=Template:Cpptutorial_Pointers&amp;diff=3591&amp;oldid=prev</id>
		<title>Root: /* Passing functions as pointers */</title>
		<link rel="alternate" type="text/html" href="https://assela.pathirana.net/index.php?title=Template:Cpptutorial_Pointers&amp;diff=3591&amp;oldid=prev"/>
		<updated>2007-06-08T13:07:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Passing functions as pointers&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Pointers=&lt;br /&gt;
The concept of pointers in a simple one; however, in old [http://en.wikipedia.org/wiki/C_language C language] the pointers are perhaps the single most common cause of program failure in code written by novice  programmers. A good way to start, eh? Well.. pointers can be trouble makers, but the good news is, unlike in C, with C++ there many ways to avoid using them. Before we go any further, the rule of the game of pointers (at least for the &amp;#039;rest of us&amp;#039;) is &amp;#039;&amp;#039;&amp;#039;don&amp;#039;t use them unless absolutely necessary&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
Having said that, using &amp;#039;Pointers&amp;#039; for essential tasks is not difficult, and the rules that govern how they work are pretty simple. The rules can be combined to get complex results, but the individual rules remain simple.&lt;br /&gt;
&lt;br /&gt;
Before we go any further, lets define what a `pointer&amp;#039; is.&lt;br /&gt;
;Pointer:A pointer is a programming language data type whose value refers directly to (or “points to”) another value stored elsewhere in the computer memory using its address.&lt;br /&gt;
&lt;br /&gt;
A good analogy is the relationship between a web page and its URL (address). For example &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;http://en.wikipedia.org/wiki/Banana&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; is URL of the page describing Bananas on Wikipedia. If we know the above address it allows us to reach the &amp;#039;&amp;#039;Banana Page&amp;#039;&amp;#039;. However, &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;http://en.wikipedia.org/wiki/Banana&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; is not the &amp;#039;&amp;#039;Banana Page&amp;#039;&amp;#039;, but only the &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;address&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; of that page. &lt;br /&gt;
&lt;br /&gt;
Similarly a pointer in computer jargon is a reference (or address) of something. &lt;br /&gt;
&lt;br /&gt;
===Pointers and Pointees===&lt;br /&gt;
&lt;br /&gt;
Remember this: Addresses are pointers. The stuff referred to by those addresses (&amp;#039;&amp;#039;Banana Page&amp;#039;&amp;#039; in case of &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;http://en.wikipedia.org/wiki/Banana&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; or your home, in case of your postal address.) is pointee. &lt;br /&gt;
&lt;br /&gt;
In C/C++ we denote this as follows: &lt;br /&gt;
&amp;lt;source lang=cpp&amp;gt;&lt;br /&gt;
/* Pointer/ Pointee demo */&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(){&lt;br /&gt;
	int *k; // the pointee of k is an integer. &lt;br /&gt;
	int y;  // y is an integer&lt;br /&gt;
	y=0;    // set y to zero&lt;br /&gt;
	k=&amp;amp;y;   // point k to the address of y (y is pointee of k now)&lt;br /&gt;
	*k=40;  // set the value of pointee of k (ah, ha!) to 40. &lt;br /&gt;
	cout &amp;lt;&amp;lt; y &amp;lt;&amp;lt;&amp;quot;\n&amp;quot;; // print y. &lt;br /&gt;
	cout &amp;lt;&amp;lt; (*k) &amp;lt;&amp;lt;&amp;quot;\n&amp;quot;; // print pointee of k&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The notation  &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; can be read as &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;pointee of&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; and &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;&amp;amp;&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; as &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;address of&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
What &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt; k=&amp;amp;y; *k=40; &amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; does is equivalent of &amp;lt;tt&amp;gt;&amp;lt;nowiki&amp;gt;y=40&amp;lt;/nowiki&amp;gt;&amp;lt;/tt&amp;gt; in a very round about way!! This code shows one of the major issues of pointer usage. Where there are pointers -- there are hidden links. If we don&amp;#039;t keep a track of these links, we are inviting for trouble!&lt;br /&gt;
&lt;br /&gt;
If you are interested in a more in-depth coverage of the pointers in general make a detour to [[C++ Pointers -- Advanced|this link]]. The rest of this article covers only two important aspects of pointers.&lt;br /&gt;
&lt;br /&gt;
==Using Pointers to get values out of functions==&lt;br /&gt;
The most straight forward way to get the results of a function is its return value. If you need to get several values out of a function how do you do that? One way is to use [[#Data_Structures|Data Structures]], a topic we are yet to cover. Another is to use pointers. See the following example: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=cpp&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
void add(int *a){ // pointee of a is an integer&lt;br /&gt;
	(*a)+=5;		  // add 5 to pointee of a&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
	int val=0;      // val is zero&lt;br /&gt;
        int *k;  // k&amp;#039;s pointee is an integer. &lt;br /&gt;
	k=&amp;amp;val;  //now k points to the address of val&lt;br /&gt;
	add(k);      // pass k, i.e. address of val&lt;br /&gt;
	cout &amp;lt;&amp;lt; val;    // val has changed! &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following section is a formal explanation of what is happening. &lt;br /&gt;
&lt;br /&gt;
===Passing &amp;#039;&amp;#039;by value&amp;#039;&amp;#039; or &amp;#039;&amp;#039;by reference&amp;#039;&amp;#039;===&lt;br /&gt;
&lt;br /&gt;
All the simple functions we have seen in section [[#Functions|Functions]] and thereafter, the arguments passed to the functions have been passed &amp;#039;&amp;#039;by value&amp;#039;&amp;#039;. This means that when calling a function with parameters, what we have passed to the function were copies of their values but never the variables themselves. For example in the followng code&lt;br /&gt;
&amp;lt;source lang=cpp&amp;gt;&lt;br /&gt;
// function example&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int addition (int a, int b)&lt;br /&gt;
{&lt;br /&gt;
  int r;&lt;br /&gt;
  r=a+b;&lt;br /&gt;
  return (r);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
  int z;&lt;br /&gt;
  z = addition (5,3);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;The result is &amp;quot; &amp;lt;&amp;lt; z;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What we did in this case was to call to function addition passing the values of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt;, i.e. &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; respectively, but not the variables &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; themselves.&lt;br /&gt;
&lt;br /&gt;
[[Image:8-imgfunc1.gif]]&lt;br /&gt;
&lt;br /&gt;
This way, when the function addition is called, the value of its local variables &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; become &amp;lt;tt&amp;gt;5&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; respectively, but any modification to either &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; within the function addition will not have any effect in the values of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; outside it, because variables &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; were not themselves passed to the function, but only copies of their values at the moment the function was called.&lt;br /&gt;
&lt;br /&gt;
But there might be some cases where you need to manipulate from inside a function the value of an external variable. For that purpose we can use arguments passed by reference, as in the function duplicate of the following example:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;codebox&amp;quot;&lt;br /&gt;
| class=&amp;quot;code&amp;quot; |&lt;br /&gt;
 &amp;lt;span class=&amp;quot;comm&amp;quot;&amp;gt;// passing parameters by reference&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;prep&amp;quot;&amp;gt;&amp;lt;nowiki&amp;gt;#include &amp;lt;iostream&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;using&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;namespace&amp;lt;/span&amp;gt; std;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;void&amp;lt;/span&amp;gt; duplicate (&amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; a, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; b, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; c)&lt;br /&gt;
 {&lt;br /&gt;
   a*=2;&lt;br /&gt;
   b*=2;&lt;br /&gt;
   c*=2;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; main ()&lt;br /&gt;
 {&lt;br /&gt;
   &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; x=1, y=3, z=7;&lt;br /&gt;
   duplicate (x, y, z);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;lt;span class=&amp;quot;str&amp;quot;&amp;gt;&amp;quot;x=&amp;quot;&amp;lt;/span&amp;gt; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &amp;lt;span class=&amp;quot;str&amp;quot;&amp;gt;&amp;quot;, y=&amp;quot;&amp;lt;/span&amp;gt; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;lt;span class=&amp;quot;str&amp;quot;&amp;gt;&amp;quot;, z=&amp;quot;&amp;lt;/span&amp;gt; &amp;lt;&amp;lt; z;&lt;br /&gt;
   &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;return&amp;lt;/span&amp;gt; 0;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
| class=&amp;quot;result&amp;quot; |&lt;br /&gt;
 x=2, y=6, z=14&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The first thing that should call your attention is that in the declaration of &amp;lt;tt&amp;gt;duplicate&amp;lt;/tt&amp;gt; the type of each parameter was followed by an ampersand sign (&amp;lt;tt&amp;gt;&amp;amp;&amp;lt;/tt&amp;gt;). This ampersand is what specifies that their corresponding arguments are to be passed &amp;#039;&amp;#039;by reference&amp;#039;&amp;#039; instead of &amp;#039;&amp;#039;by value&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
When a variable is passed by reference we are not passing a copy of its value, but we are somehow passing the variable itself to the function and any modification that we do to the local variables will have an effect in their counterpart variables passed as arguments in the call to the function.&lt;br /&gt;
&lt;br /&gt;
[[Image:8-imgfunc3.gif]]&lt;br /&gt;
&lt;br /&gt;
To explain it in another way, we associate &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; with the arguments passed on the function call (&amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;z&amp;lt;/tt&amp;gt;) and any change that we do on &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; within the function will affect the value of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt; outside it. Any change that we do on &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; will affect &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt;, and the same with &amp;lt;tt&amp;gt;c&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;z&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
That is why our program&amp;#039;s output, that shows the values stored in &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;z&amp;lt;/tt&amp;gt; after the call to &amp;lt;tt&amp;gt;duplicate&amp;lt;/tt&amp;gt;, shows the values of all the three variables of &amp;lt;tt&amp;gt;main&amp;lt;/tt&amp;gt; doubled.&lt;br /&gt;
&lt;br /&gt;
If when declaring the following function:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;snippet&amp;quot;&lt;br /&gt;
| class=&amp;quot;code&amp;quot; |&lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;void&amp;lt;/span&amp;gt; duplicate (&amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; a, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; b, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; c)&lt;br /&gt;
 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
we had declared it this way:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;snippet&amp;quot;&lt;br /&gt;
| class=&amp;quot;code&amp;quot; |&lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;void&amp;lt;/span&amp;gt; duplicate (&amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; a, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; b, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; c)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
i.e., without the ampersand signs (&amp;lt;tt&amp;gt;&amp;amp;&amp;lt;/tt&amp;gt;), we would have not passed the variables by reference, but a copy of their values instead, and therefore, the output on screen of our program would have been the values of &amp;lt;tt&amp;gt;x&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;y&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;z&amp;lt;/tt&amp;gt; without having been modified.&lt;br /&gt;
&lt;br /&gt;
Passing by reference is also an effective way to allow a function to return more than one value. For example, here is a function that returns the previous and next numbers of the first parameter passed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;codebox&amp;quot;&lt;br /&gt;
| class=&amp;quot;code&amp;quot; |&lt;br /&gt;
 &amp;lt;span class=&amp;quot;comm&amp;quot;&amp;gt;// more than one returning value&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;prep&amp;quot;&amp;gt;&amp;lt;nowiki&amp;gt;#include &amp;lt;iostream&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;using&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;namespace&amp;lt;/span&amp;gt; std;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;void&amp;lt;/span&amp;gt; prevnext (&amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; x, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; prev, &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt;&amp;amp; next)&lt;br /&gt;
 {&lt;br /&gt;
   prev = x-1;&lt;br /&gt;
   next = x+1;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; main ()&lt;br /&gt;
 {&lt;br /&gt;
   &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;int&amp;lt;/span&amp;gt; x=100, y, z;&lt;br /&gt;
   prevnext (x, y, z);&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;lt;span class=&amp;quot;str&amp;quot;&amp;gt;&amp;quot;Previous=&amp;quot;&amp;lt;/span&amp;gt; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; &amp;lt;span class=&amp;quot;str&amp;quot;&amp;gt;&amp;quot;, Next=&amp;quot;&amp;lt;/span&amp;gt; &amp;lt;&amp;lt; z;&lt;br /&gt;
   &amp;lt;span class=&amp;quot;kw&amp;quot;&amp;gt;return&amp;lt;/span&amp;gt; 0;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
| class=&amp;quot;result&amp;quot; |&lt;br /&gt;
 Previous=99, Next=101&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Passing functions as pointers==&lt;br /&gt;
;Note: This section can be skipped without much harm! &lt;br /&gt;
&lt;br /&gt;
We can pass whole functions as arguments to other functions using pointers. See the following example. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=cpp&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int oper(int one, int two, int (*myfunc)(int,int)){ // pointee of myfunc is a function &lt;br /&gt;
						    //and takes two integer arguments&lt;br /&gt;
						    // and return an integer. &lt;br /&gt;
	return (*myfunc)(one,two);		    // &amp;amp;x - &amp;#039;pointer of x is..&amp;#039;&lt;br /&gt;
						    // *x - &amp;#039;pointee of x is..&amp;#039;&lt;br /&gt;
										&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int bigger(int a, int b){&lt;br /&gt;
	if(a&amp;gt;b){&lt;br /&gt;
		return a;&lt;br /&gt;
	}else{&lt;br /&gt;
		return b;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int smaller(int a, int b){&lt;br /&gt;
	if(a&amp;gt;b){&lt;br /&gt;
		return b;&lt;br /&gt;
	}else{&lt;br /&gt;
		return a;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
	int a=5, b=10;&lt;br /&gt;
	cout &amp;lt;&amp;lt; oper(a,b,&amp;amp;bigger)&amp;lt;&amp;lt;&amp;#039;\n&amp;#039;;&lt;br /&gt;
	cout &amp;lt;&amp;lt; oper(a,b,&amp;amp;smaller)&amp;lt;&amp;lt;&amp;#039;\n&amp;#039;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Root</name></author>
	</entry>
</feed>