<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Theja sree on Medium]]></title>
        <description><![CDATA[Stories by Theja sree on Medium]]></description>
        <link>https://medium.com/@teja810652?source=rss-6c0d1b743175------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WlLJ9I8EFBRCQSX9</url>
            <title>Stories by Theja sree on Medium</title>
            <link>https://medium.com/@teja810652?source=rss-6c0d1b743175------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 08:44:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@teja810652/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Call by Value vs Call by Reference in C — A Simple Explanation for Beginners]]></title>
            <link>https://medium.com/@teja810652/call-by-value-vs-call-by-reference-in-c-a-simple-explanation-for-beginners-0e95d12da4a0?source=rss-6c0d1b743175------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e95d12da4a0</guid>
            <category><![CDATA[call-by-value]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[programming-for-beginners]]></category>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[call-by-reference]]></category>
            <dc:creator><![CDATA[Theja sree]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 15:57:02 GMT</pubDate>
            <atom:updated>2025-08-03T15:58:00.364Z</atom:updated>
            <content:encoded><![CDATA[<h3>Call by Value vs Call by Reference in C — A Simple Explanation for Beginners</h3><p>Hello everyone!<br>This week I learned something very interesting in C programming: <strong>Call by Value</strong> and <strong>Call by Reference</strong>.</p><p><strong>It was confusing at first, but now I understand, so I’ll explain it in a simple way.</strong></p><p>So, I’m here to explain it in a simple way that anyone can understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*Lt3kc9b4Kac4G93m5yyNNA.png" /></figure><h3><strong>What is Call by Value?</strong></h3><p><strong>Definition : —</strong></p><p>In Call by Value, a copy of the variable is given to the function.</p><p>That means the real value doesn’t change, even if the copy changes inside the function.</p><h4><strong>Let’s understand with real world example : -</strong></h4><p>Imagine you have a <strong>toy car</strong>.<br> Your little brother wants to play with it, but instead of giving him your real toy, you give him a <strong>duplicate plastic car</strong> .</p><p>Now, if he breaks or paints it — no problem!<br> <strong>Your original toy is still safe in your cupboard.</strong></p><p>That’s exactly what happens in <strong>Call by Value</strong> — the function gets a copy, so the <strong>original stays unchanged</strong>.</p><p><strong><em>Simple Code:</em></strong></p><pre>#include &lt;stdio.h&gt;<br>void change(int x) {<br>    x = 100;<br>}<br>int main() {<br>    int a = 10;<br>    change(a);<br>    printf(&quot;a = %d&quot;, a); // Output: 10<br>    return 0;<br>}</pre><p><strong>How This Code Works : -</strong></p><p>When you run this program, the computer behaves like a little helper robot 👨‍💻 who follows instructions</p><h4><em>step by step:-</em></h4><pre>int a = 10;</pre><p>The computer saves a number 10 in a small box called a.</p><pre>change(a);</pre><p>The robot says:</p><p>“Hey! Let me send a copy of this value (10) to the change function.”</p><pre>  void change(int x) {<br>      x = 100;<br>    }</pre><p>A new box called x is made. The robot puts 10 in it.<br>Then it says: “Now I’ll change x to 100.”</p><p>BUT Nothing happens to a because it’s only the copy that changed.</p><pre>printf(&quot;a = %d&quot;, a);</pre><p>Finally, the robot looks back at box a and says:</p><p>“Still 10! I’ll print it.”</p><h4><strong><em>Output : -</em></strong></h4><pre>a = 10</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*fzJHTLhLPbGdKMuGIlIZkw.png" /></figure><p>We saw that <strong>Call by Value</strong> keeps the original safe — just like giving your brother a <strong>duplicate toy</strong>.<br>But what if you actually <strong>want your original toy to get painted or fixed</strong>?</p><p>In programming, sometimes we <strong>do</strong> want the function to change the real value.</p><p>So how can we do that?</p><p>Well… that’s where <strong>Call by Reference</strong> comes in!</p><p>It’s like saying:</p><p>“Hey function, here’s the <strong>actual toy</strong> — not a copy. You can play with it, change it, or fix it!”</p><h3><strong>What is Call by Reference?</strong></h3><p><strong>Definition : —</strong></p><p>In Call by Reference, we don’t send a copy — we send the original thing itself to the function.</p><p>So, if the function changes it, the real value <strong>will change</strong> too!</p><h4><strong>Let’s understand with real world example : -</strong></h4><p>Imagine you have a toy car.</p><p>Your little brother wants to play with it, so this time, you give him your <strong>real toy</strong>, not a duplicate.</p><p>He paints it red, removes the wheels, and puts stickers on it.</p><p>Later, when you take it back, your toy car looks completely different!</p><p><strong>Why?</strong></p><p>Because he used your <strong>real toy</strong>, not a copy.</p><p>That’s exactly what happens in <strong>Call by Reference</strong> — the function uses the original, so any changes made are permanent!</p><p><strong><em>Simple Code:</em></strong></p><pre>#include &lt;stdio.h&gt;<br>void change(int *x) {<br>    *x = 100;<br>}<br>int main() {<br>    int a = 10;<br>    change(&amp;a);<br>    printf(&quot;a = %d&quot;, a); // Output: 100<br>    return 0;<br>}</pre><p><strong>How This Code Works : -</strong></p><p>Think of the computer as a little helper robot 🧑‍💻 who follows instructions carefully:</p><pre>int a = 10;</pre><p>The robot creates a box named a and puts the number 10 inside.</p><pre>change(&amp;a);</pre><p>The robot says:<br> “Let me send the address of box a to the change() function — not just the value!”</p><p>This is like saying:<br> “Hey function! Here’s the real location of the value. You can change it directly!”</p><pre>void change(int *x) {<br>*x = 100;<br>}</pre><p>Now inside the function:</p><ul><li>The robot sees a pointer x, which is holding the address of a.</li><li>*x = 100; means:<br> Go to that address and put 100 inside the real box.</li></ul><p>So now, the original value in a is changed from 10 to 100!</p><pre>printf(&quot;a = %d&quot;, a);</pre><p>The robot checks box a and says:</p><p>“Wow, it’s now 100! Let me print it.”</p><p><strong>OUTPUT : -</strong></p><pre>a = 100</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*YawggcdFd7VLB_0Z7QrNrQ.png" /></figure><h4><strong><em>conclusion : —</em></strong></h4><p><strong>At first, I didn’t understand what Call by Value and Call by Reference meant.</strong><br> But now, after learning and practicing, I understand the difference clearly.</p><p><strong>I hope this helps others who are also confused in the beginning.</strong><br> Keep learning — step by step, it gets easier 😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e95d12da4a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>