Friday 28 February 2014

Explain function with example.

Function-A function is a sub block with one or two statments which perform a task when called.Whenever a fucntion is called control passes to called function from calling function.Control returns back to calling function only when execution is done.The values of actual arguments are passed to formal arguments by calling function.
The function performs on formal arguments.
Syntax
functionname(arguments)
    {
    local variable declaration;
    stmt;
    return value;
    }
Write a program to show how a function is called.
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int x=1,y=2,z;
z=add(x,y); //calling function with actual arguments x,y//
printf("z=%d",z);
}
add(a,b)
{
return(a+b);//called function with formal arguments a,b//
}

No comments:

Post a Comment