<?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 Shivanibaiju on Medium]]></title>
        <description><![CDATA[Stories by Shivanibaiju on Medium]]></description>
        <link>https://medium.com/@shivanibaiju?source=rss-cc38864c1807------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GAPSr8LzaFNmzwIQ</url>
            <title>Stories by Shivanibaiju on Medium</title>
            <link>https://medium.com/@shivanibaiju?source=rss-cc38864c1807------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:24:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shivanibaiju/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[Understanding Functions in C: Building Modular and Efficient Programs]]></title>
            <link>https://medium.com/@shivanibaiju/understanding-functions-in-c-building-modular-and-efficient-programs-d18e163e66e6?source=rss-cc38864c1807------2</link>
            <guid isPermaLink="false">https://medium.com/p/d18e163e66e6</guid>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[c-programming]]></category>
            <dc:creator><![CDATA[Shivanibaiju]]></dc:creator>
            <pubDate>Tue, 22 Sep 2026 06:55:35 GMT</pubDate>
            <atom:updated>2026-09-22T06:55:35.846Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C9NeN9xfXRucFVgvRdrsaw.jpeg" /></figure><p>Introduction</p><p>When we start learning C programming, programs can become confusing when everything is written inside the “main()” function. This is where functions become useful.</p><p>A function is a block of code that is created to perform a particular task. Instead of writing the same code again and again, we can write it once inside a function and call it whenever we need it.</p><p>For example, if we want to calculate the area of a square several times, we can create a function called “squareArea()” and use it whenever required.</p><p>In simple words:</p><p>Function = Write once + Use whenever needed</p><p>Why Do We Use Functions?</p><p>Functions make a program easier to understand and manage.</p><p>Some important advantages are:</p><p>- Reduces repetition: We don’t have to write the same code multiple times.</p><p>- Makes programs easier to understand: Each function can perform one specific task.</p><p>- Easy debugging: If there is an error, we can check the particular function.</p><p>- Code reusability: A function can be called many times.</p><p>- Better organization: Large programs can be divided into smaller parts.</p><p>For example, a student management program can have separate functions for:</p><p>“addStudent()” → adds student details</p><p>“displayStudent()” → displays student details</p><p>“calculateMarks()” → calculates marks</p><p>This makes the program much cleaner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onzuPgP8m1bR9hZHchSQAQ.jpeg" /></figure><p>Basic Structure of a Function</p><p>A function generally looks like this:</p><p>return_type function_name(parameters)</p><pre>{<br>// statements<br>return value;<br>}<br>For example:<br>int add(int a, int b)<br>{<br>return a + b;<br>}</pre><p>Here:</p><p>- “int” → return type</p><p>- “add” → function name</p><p>- “a” and “b” → parameters</p><p>- “return a + b” → returns the result</p><p>Types of Functions in C</p><p>Functions can mainly be divided into two categories:</p><p>1. Library Functions</p><p>These are functions that are already provided by C.</p><p>Some examples are:</p><p>printf()</p><p>scanf()</p><p>strlen()</p><p>sqrt()</p><p>For example, “printf()” is used to display output on the screen.</p><p>2. User-Defined Functions</p><p>These are functions created by the programmer according to the requirements of the program.</p><p>Example:</p><pre>void greet()<br>{<br>printf(&quot;Hello, BCA students!&quot;);<br>}</pre><p>We can call this function from “main()”.</p><p>Four Common Types of User-Defined Functions</p><p>1. No Arguments and No Return Value</p><p>The function does not take any input and does not return a value.</p><pre>#include<br>void message()<br>{<br>printf(&quot;Welcome to C Programming!&quot;);<br>}<br>int main()<br>{<br>message();<br>return 0;<br>}</pre><p>Here, “message()” simply prints a statement.</p><p>2. Arguments but No Return Value</p><p>The function receives values but does not return a result.</p><pre>#include<br>void displaySum(int a, int b)<br>{<br>printf(&quot;Sum = %d&quot;, a + b);<br>}<br>int main()<br>{<br>displaySum(10, 20);<br>return 0;<br>}</pre><p>The values “10” and “20” are passed to the function.</p><p>Output:</p><p>Sum = 30</p><p>3. No Arguments but Returns a Value</p><p>The function does not receive values but returns a result.</p><pre>#include<br>int getNumber()<br>{<br>return 50;<br>}<br>int main()<br>{<br>int n;<br>n = getNumber();<br>printf(&quot;Number = %d&quot;, n);<br>return 0;<br>}</pre><p>Here, “getNumber()” returns the value “50”.</p><p>4. Arguments and Return Value</p><p>This type accepts values and also returns a result.</p><pre>#include<br>int multiply(int a, int b)<br>{<br>return a * b;<br>}<br>int main()<br>{<br>int result;<br>result = multiply(5, 4);<br>printf(&quot;Result = %d&quot;, result);<br>return 0;<br>}</pre><p>Output:</p><p>Result = 20</p><p>This type is especially useful when we need to perform calculations.</p><p>Function Prototype</p><p>A function prototype tells the compiler about a function before it is used.</p><p>Example:</p><p>int add(int, int);</p><p>The complete program can be written as:</p><pre>#include<br>int add(int, int);<br>int main()<br>{<br>int result;<br>result = add(5, 7);<br>printf(&quot;Sum = %d&quot;, result);<br>return 0;<br>}<br>int add(int a, int b)<br>{<br>return a + b;<br>}</pre><p>The prototype helps the compiler understand what type of values the function will receive and return.</p><p>Function Calling</p><p>Creating a function is not enough. We need to call it to execute its statements.</p><p>For example:</p><pre>void hello()<br>{<br>printf(&quot;Hello!&quot;);<br>}</pre><p>Calling the function:</p><p>hello();</p><p>When “hello()” is called, the statements inside the function are executed.</p><p>A simple flow can be understood as:</p><p>main() → function call → function executes → result → back to main()</p><p>A Simple Real-Life Example</p><p>Functions can be compared to different departments in a college.</p><p>For example:</p><p>College Program</p><p>- Admission Function</p><p>- Attendance Function</p><p>-Marks Function</p><p>-Result Function</p><p>Each function has a separate job, but together they help complete the whole program.</p><p>Similarly, instead of putting every task inside “main()”, we can divide a large program into smaller functions.-</p><p>My Own Example: Simple Calculator</p><p>A simple calculator can use different functions for different operations.</p><pre>#include<br>int add(int a, int b)<br>{<br>return a + b;<br>}<br>int subtract(int a, int b)<br>{<br>return a - b;<br>}<br>int multiply(int a, int b)<br>{<br>return a * b;<br>}<br>int main()<br>{<br>int a = 20, b = 5;<br>printf(&quot;Addition = %d\n&quot;, add(a, b));<br>printf(&quot;Subtraction = %d\n&quot;, subtract(a, b));<br>printf(&quot;Multiplication = %d\n&quot;, multiply(a, b));<br>return 0;<br>}</pre><p>Output:</p><p>Addition = 25</p><p>Subtraction = 15</p><p>Multiplication = 100</p><p>Here, each operation has its own function. If we want to add another operation such as division, we can create another function without disturbing the existing functions.</p><p>Important Terms to Remember</p><p>Term: Meaning</p><p>Function: Block of code used for a specific task</p><p>Function name: Name used to identify the function</p><p>Parameter: Variable that receives a value</p><p>Argument: Actual value passed to a function</p><p>Return value: Value sent back by the function</p><p>Function call: Statement used to execute a function</p><p>Prototype: Declaration of a function before its use</p><p>Conclusion</p><p>Functions are an important part of C programming because they help us divide a large program into smaller and manageable parts.</p><p>As a first-year BCA student, I find functions useful because they make programs less confusing and reduce repeated code. They also make debugging and understanding a program easier.</p><p>The main idea I learned is that a good program does not have to put everything in one place. Different tasks can be given to different functions, and those functions can work together to complete the program.</p><p>So, instead of creating one giant “main()” function that looks like it has been through three semesters of trauma, we can divide the work into smaller functions and keep the program organized.</p><p>Key Takeaway</p><p>Functions help us write C programs that are reusable, organized, readable, and easier to maintain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d18e163e66e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>