Unit 6. Functions with Pavan Chavhan



Hello everyone !!! Once again welcome to "technical_spc". I hope all the topics covered in the previous blog are clear to all of you. If having any doubts you can contact me using the contact form or also you can put it in comments. So, in the last blog we have completed a most important topic i.e. String. Today we are going to cover another important part i.e. Function.


Introduction

👉 we can divide a large program into the basic building blocks known as function.

👉The function contains the set of programming statements enclosed by {}.

👉A function can be called multiple times to provide reusability and modularity to the C program. 

👉The function is also know as procedure or subroutine in other programming languages.


Advantages of function in "C"

👉By using functions, we can avoid rewriting same logic/code again and again in a program.

👉We can call C functions any number of times in a program and from any place in a program.

👉We can track a large C program easily when it is divided into multiple functions.

👉Reusability is the main achievement of C functions.

👉However, Function calling is always a overhead in a C program.


Types of functions 




👉Library Functions :- are the functions which are declared in the C header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc.


👉User-defined functions :- are the functions which are created by the C programmer, so that he/she can use it many times. It reduces the complexity of a big program and optimizes the code.
 

Library Functions 



User Defined Functions 


👉Function declaration : A function must be declared globally in a c program to tell the compiler about the function name, function parameters, and return type.
👉Function call : Function can be called from anywhere in the program. The parameter list must not differ in function calling and function declaration. We must pass the same number of functions as it is declared in the function declaration.
👉Function definition : It contains the actual statements which are to be executed. It is the most important aspect to which the control comes when the function is called. Here, we must notice that only one value can be returned from the function.

Syntax of creating function 



return_type function_name(data_type parameter...)
         {  
           //code to be executed  
          }  


Different aspects of function calling 


👉 function with arguments and with return value
👉 function without arguments and with return value
👉 function without arguments and without return value
👉 function with arguments and without return value


Example :-

  • Program :-



  • Output :-



Recursion Function 


A function that calls itself is known as a recursive function. And, this technique is known as recursion.

Syntax :-

       int main() 
          { ... .. ... 
              recurse(); 
              ... .. ... 
           }
         void recurse() 
         { ... .. ... 
           recurse();
            ... .. ... 
            } 





Example :-

  • Program :-


  • Output :-




If you have any questions you may ask in comment below. If you enjoyed this article, share it with your friends and colleagues!





Join our telegram channel and WhatsApp group to get all the updates.


👍Telegram link :- https://telegram.me/spchavhan


👍WhatsApp link :- https://chat.whatsapp.com/G5kJUnaC1Gg4JpDz4kwEpy







Post a Comment

0Comments

If you have any doubts, Please let me know

Post a Comment (0)