+1 vote
in Class 11 by kratos

Explain the structure of a function.

1 Answer

+6 votes
by kratos
 
Best answer

Function type function name (data-type arg1, data-type arg2, … datatype argn)

{

variable declarations;

statement 1;

statement 2;

……..

statement n;

return(expression);

}

1. Function_type:

The function-type identifies the type of return value, which will be sent back after the function has performed its task. Eg: function type may be an int, float, char, void.

2. Function_name:

Function name followed by a pair of open and close parentheses ‘()’ helps to identify the name of the function and its arguments. () The parentheses can contain an optional list of arguments that are passed to the function. Arguments are used to transfer/copy (pass) the values from calling function to called function.

3. Body of the function:

It is enclosed within braces. A function should have at least one executable statement and rest of the things are same as in main( ) function. The body of the function can also have an optional declaration for the variables to be used by the function only also called as local variables.

4. Return(expression):

The return statement can return the value of any expression. The return statement can contain an optional expression or value that is to be returned back to the calling function.

...