Search This Blog
Monday, June 11, 2012
Parts of a function
Parts of a function
A function basically consists of two parts: Function header and Body.
Header
The header consists of three parts: Function return type, Function name and Parameter list.
E.g. Return Type Function Name (Parameter List)
The function return type can be any of C’s data types: int, float, char, long etc. You can also define
a function that does not return a value by using ‘void’.
E.g. void function(…) Returns nothing
Note: function(void) Returns no argument
Arguments and Parameters
An argument is an actual value passed to the function by calling program. Parameter is an entry in a function header. It acts as the placeholder for an argument. Parameters of a function are fixed and do not change during program execution.
Body
Function body is the part that is enclosed in braces {…}. The body contains the statements that perform the actual work. When a function is called, execution begins at the start of the body and continues until a return statement or a closing brace is reached. The return statement not only terminates a function but also returns the value to the calling program if any. A function can contain multiple return statements. The first return is the only one that has any effect.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment