Showing posts with label FUNCTIONS. Show all posts
Showing posts with label FUNCTIONS. Show all posts

Sunday, October 5, 2014

call by value and call by reference

 Brief call by value and call by reference in detail. (MAY 2009)

Call by value:
In call by value the value of the actual arguments are passed to the formal arguments and the operation is done on formal arguments.
Example program:
· To send two integer values using “call by value”.
Call by reference:
In call by reference the address of actual argument values are passed to formal argument values.
Example program:

· To send a value by reference to user defined function.

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.