Advertisement

Functions in C++ || Code with abuzar

 

                       Functions in C++ 

    In this tutorial you will learn about functions and examples 


A function is a group of statements that perform a task . Every program tha has a function , which is main(). and all the program can define additinal functions.

You can divide up your code into seprate functions . but logically is such that each function perform specific task .

C++ User defined functions 

C++ allows the programmer to define their own function .A user define function perform a specific task and that group of code is given a number(Identifier).

When the function is involked from any parts of the program , it all executed the codes defined in the body of the function .

Syntax to decalre the function 


Return type functionName ( parameter1 , parameter2 ....){

// Function body

}

This is the example of function declaration 


Example :

#include<iostream>
using namesapce std;
int sumint a , int b ){
int c = a*b;
return c;
}
int main(){
Int  num1 , num2 ;
cout<<"Enter the first number "<<endl;
cin>>num1;
cout<<"Enter the second number "<<endl;
cin>>num2 ;
cout<<"Your answer is \n"<<sum(num1 ,num2);
return 0;
}


Output  :

Enter your first number number  2

Enter your second number 5

Your answer is 10


C++ User defined functions 

Functions is used when we do different task on same platform so we use functions in c++ the role of function is very important . Suppose you make a application where you can do many types of work like editing , green effect and much more . so in this case you have to used functions .


Benefit of using user define-function

  • function make the code reusable . We can declare them once and use them multiple times
  • Function make the program easier and each small task is divided into a functions .
  • Function increase readability.

       RELATED ARTICLE 

 Function in C++ Video : Click Here 

 This is my YouTube channel : Click Here  

 Playlist of C++(Full Course) : Click Here

 Playlist of C++(Program ) : Click Here
 
 Please ! write comment if you find anything incorrect in this website .


 This article is contributed by Mohd abuzar . If you want to like code with abuzar or want to contribute with us so mail at - abuzar.abuzar.mohd325@gmail.com


Post a Comment

0 Comments