<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>call by reference in c++ | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/call-by-reference-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Wed, 28 Dec 2022 15:37:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Methods of Function -Part II</title>
		<link>https://studentprojects.in/software-development/cpp/methods-of-function-part-ii/</link>
					<comments>https://studentprojects.in/software-development/cpp/methods-of-function-part-ii/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Tue, 10 Jan 2023 15:32:54 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[call by reference in c++]]></category>
		<category><![CDATA[c++ default arguments]]></category>
		<category><![CDATA[c++ constant argument]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10083</guid>

					<description><![CDATA[<p>3. Call by Reference in C++ In C++, there is a way for passing values to function arguments called &#8220;call by reference.&#8221; When a function is called by reference, the formal parameter receives a reference to the actual parameters, which means that modifying the function&#8217;s internal values will also change the parameters&#8217; actual values. The</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/methods-of-function-part-ii/">Methods of Function -Part II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<h3>3. Call by Reference in C++</h3>



<p>In C++, there is a way for passing values to function arguments called &#8220;call by reference.&#8221; When a function is called by reference, the formal parameter receives a reference to the actual parameters, which means that modifying the function&#8217;s internal values will also change the parameters&#8217; actual values. The following is an illustration of the call by reference approach:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
void swap(int &amp;a, int &amp;b)
{
    int temp = a;
    a = b;
    b = temp;
}
 
int main()
{
    int x = 5, y = 6;
    cout &lt;&lt; "The value of x is " &lt;&lt; x &lt;&lt; " and the value of y is " &lt;&lt; y &lt;&lt; endl;
    swap(x, y);
    cout &lt;&lt; "The value of x is " &lt;&lt; x &lt;&lt; " and the value of y is " &lt;&lt; y &lt;&lt; endl;
}</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">The value of x is 5 and the value of y is 6
The value of x is 6 and the value of y is 5</code></pre>



<h3>4. C++&#8217;s default arguments</h3>



<p>If we don&#8217;t provide our value as a parameter, the function will utilise the default arguments. Writing default arguments after other arguments is advised.</p>



<p>Using the default argument as an example</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">int sum(int a = 5, int b);</code></pre>



<h3>5. C++ Constant Arguments</h3>



<p>When you don&#8217;t want your values to be altered by the function, you should use constant parameters. To make the parameters unmodifiable, use the const keyword.</p>



<p>An illustration utilising a constant argument,</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">int sum(const int a, int b);</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/methods-of-function-part-ii/">Methods of Function -Part II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/methods-of-function-part-ii/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
