Function in C – Concept of function, function definition, function prototype

Function in C- Concept of function, function definition, function prototype,,

             A function is a group of statement that together perform a specific task. Function is a block or part of program. A function definition specifies the name of the function, the type and number or part of parameter, it expects to receive , and its return type, when any program is very long or same code is repeating many times then we are trying to cut the program in different part of block so the whole program become more understandable , easier to debug (error checking ) and size of code will be easier. A repeated group of instruction in a program can be organized in a function  .



Why Function?

              Function are dividing a large code into module, due to this we can easily debug and maintain the code. For example if we write a calculator program at the time we can write every logic in sequence function ( For addition sum(), for subtraction sum() ). Any function can be called at any time.


Advantage of Function:
  • Code re-usability.
  • Develop an application in module format.¬†
  • Easy to debug the program.
  • Code optimization. No need to write a lot of code.
  • Code is easy to read.
  • Program testing being easy.
  • Compiled executable in smaller.
  • You dont’ have to make comments because function name make sense.¬†

Defining a Function:

Defining of function is nothing but give body of function that means write logic inside function body.



return_type_function (parameter)
  function body;

Return Type:

A function may return a value . The  return type is the data type of the value the function return. Return type parameter and return statement are optional.

Function Name:

Function name is the name  of  function . It is decided by programmer or you.

Function Body:

This is the value which is pass in function at the time of calling of function. A parameter is  like a place. It is optional holder.

Function Declaration:u

A function declaration is the process that tells the compiler about a function name. The actual body of function can be defined separately.



     Note: At the time of function declaration function name be terminated with;

Calling Function:

         When we call any function control goes to function body and execute entire code. For call any function just write name of function and  if any parameter is required then pass parameter .



function_n name(); or
variable= function_name (argument);

     Note: At the time of function calling function must be terminated with;

Example :
void sum();    // declaring a function
void main()
 int a=10, b=20,c;
 sum();     // calling function getch ();
void sum()  // defining function
 printf("n Sum:%d",c);




Leave a Reply

Your email address will not be published. Required fields are marked *