Functions in Programming
The
functions are like subtasks. They receive some information, do some procedure
and provide a result. Functions are invoked through a calling program. Calling
program does not require to know what the function is doing and how it is
performing its task. There is a specific function-calling methodology. The
calling program calls a function by giving it some information and receives the
result.
We have
a main () in every C program. ‘main()’ is also a function. When we write a
function, it must start with a name, parentheses, and surrounding braces just
like with main(). Functions are very important in code reusing.
There
are two categories of functions:
a)
Functions
that return a value
b)
Functions
that do not return a value
Suppose,
we have a function that calculates the square of an integer such that function
will return the square of the integer. Similarly we may have a function which
displays some information on the screen so this function is not supposed to
return any value to the calling program.
A
Function Structure
The
declaration syntax of a function is as follows:
Return-value-type
function-name (argument-list)
{
Declarations and statements
}
The first line is the function header
and the declaration and statement part is the body of the
function.
No comments:
Post a Comment