Showing posts with label types of functions. Show all posts
Showing posts with label types of functions. Show all posts

Tuesday, September 30, 2014

FUNCTIONS

What are functions? Explain the types of functions in detail with an example program for each type.

A function is a self contained block or a sub program of one or more statements that performs a special task when called.
Types:
· Library Functions
· User Defined functions
(a) Function Declaration
returntype function-name(Parameters);
Example:
int square(int, int);
(b) Function calling
function-name(actual parameters);
Example:
int square(a,b);

(c) Function Definition:
returntype function-name(formal parameters)
{
}

Example:
local variable declaration;
statement 1; statement 2; return(value);
void square(int a, int b)
{
printf(“%d”,(a*b));
}
Example for functions:
· Addition of two numbers where addition is a separate function
· Program using function for evaluating Fibonacci series.