Header Ads Widget

Function declaration

 1.Function declaration/ prototyping:-

                                                                   A function declaration tells the compiler following three things--

  1. Name of the Function:-   It is identifier (User define name ) given to the function.
  2. Return type:--    It is specify the data type of the value return by the function.
  3. Argument / Parameter:-  It  is specify the number if Argument along with their data type.
Example:- Consider a user define function name sum which takes as input two argument of integer types and calculate the sum of input values and then return .  The declaration of the function sum is as follow.

int sum(int x, int y);



2. Function definition:-
                                 A function definition is used to specify the sequence of the statements that are to be written in the body of the function .

Syntax:-   

Return type   Function name (Argument list)
{
    //  Body of the function 
    return  argument;

}


Example:-
              
int sum(int x , int y)
{
    int z;
    z=x+y;
    return z;
}


3.Function Calling :-

                              When ever their is a requirement of forming the task written in the function , the function is called during the execution of the program.
The syntax of calling any function is as follow :-
Syntax:-                
Fun_name (Actual_Argument_List);


Example:-
                  To call the function name 'sum ' which takes two input integer values.
sum(10,5);

Two integer values 10 and 5 are called as Actual_Argument_list.

<<Pre--what is function                                                          Example of function-- Next>>





Recommended Post:

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-