C Functions

What is function?

Block of one or more statements or a sub program which is designed for a particular task is called function.

What are the advantages of functions:

  1. The basic purpose of function is code reuse.
  2. By using functions we can develop an application in module format.
  3. When we are developing the program in module format then easily we can debug the program.
  4. By using functions we can reduce the coding part.
  5. By using functions we can keep track of what they are doing.

Syntax:

Return type function_name(parameters)
{
statement block;
return statement;
}

More About Functions:

    C program is collection of functions.

  • From any function we can invoke any other function.
  • Always compilation will takes place from top to bottom.
  • Always execution process will starts from main and ends with main only.
  • In implementation when we are calling a function which is define later for avoiding the compilation error we need to go for forward declaration i.e. prototype is required.
  • Declaration of function means need to mention return type, name of the function and taking type i.e. parameter type information.
  • In function definition first line is called function declarator or function header.
  • Always function declaration should be match function declarator.
  • In implementation whenever a function doesn’t return any values back to the calling place then specify the return type as avoid.
  • void means nothing i.e. no return value.
  • In implementation whenever a function return other than void then specify the return type as return value type i.e. one type of return value it is returning same type of return statement should be mentioned.
  • Default return type of functions is an int.
  • Default parameter type of any function is void.

User Defined Functions in C Programming

Powered by k2schools