1.

Explain the structure of a function with an example.

Answer»

{

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 a int, float, char, void.

2. Function_name:

Function name followed by a pair of open and close parentheses ‘()’ helps to identify 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 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.



Discussion

No Comment Found

Related InterviewSolutions