.1. Function declaration :
General syntax of function declaration is :
return -type function name – name ( parameter – list);
Every function must be declared before its called. A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately. A function declaration consists of four parts –
- return – type
- function name
- parameter list
- terminating semicolon
.2. Function definition –
General syntax of function definition is :
return – type function name (parameter list )
{
function- body;
}
The first line return – type function name ( parameter) is known as function header and the statement within the curly braces is called as function body.
- return – type :
return – type specifies the type of value i.e. int, char, double that function is expected to return to the calling function.
2. function – name :
function name specifies the name of the function . The function name is any valid C identifier and therefore must follow the same rule of formation as other variables in C.
3. parameter – list :
The parameter list declares the variables that will receive the data sent by calling program. They often referred to as formal parameters. These parameters are also used to send values to calling program.
4. function – body :
The function body contains the declarations and the statement i.e. algorithm necessary for performing the required task. The body is enclosed within curly braces {} and consists of three parts :
- local variable declaration
- function statement that performs the tasks of the function
- a return statement that return the value evaluated by the function
Leave a comment