Sunday 19 March 2017

Functions

Function Definition: Function is a group of statements which performs a specific task. It is also known as Sub-routine or Procedure or Method.

return_type functions name(arguments list)
{
        body of the functions
}

Here are all the parts of a function −
  • Return Type − A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
  • Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
  • Function Body − The function body contains a collection of statements that define what the function does.
·      There are two kinds of c functions:

1.  Library Functions (also known as System defined function)
1.   Library Functions are used to perform standard operations eg: squreroot of a number sqrt(x), absolute value fabs(x),scanf(),printf(),and so on.These functions are available alog with the compiler and are used along with the required header files such as math.h, stdio.h, string.h, and so on at the beginning of the programe.



2.   User defined functions are self-contained blocks of statement which are written by the user to compute a value or to perform a task.They can be called by the main() function repeatedly as per the requirement.  

No comments:

Post a Comment