Declaring and calling a function
/*
program to find area of a ring */
#include<stdio.h>
float
area();
float
area2(float r);
int
main() {
float
a1,a2,a,r;
a1=area();
printf(“enter
the radius:”);
scanf(“f”,&r);
a2=area2(r);
a=a1-a2;
prinf(“area
of ring: %3f\n”,a);
}
float
area() {
float
r;
printf(“enter
the radius:”);
scanf(“%f”,&r);
return(3.14*r*r);
}
float
area2(float r) {
return(3.14*r*r);
}
But:
How
is a function declared?
What
is a function call?
What
is a calling function?
What
is a called function?
Declaration of a function (or)
syntax of a function
return-value-type
function-name (type parameter 1, type parameter 2, ... type parameter n)
{
definitions
statements
}
A
function call is an expression that passes
control and arguments (if any) to a function.
Functions
are invoked by a function call, which specify the function name and provides
information (as arguments) that the called function needs, to perform its
designated task.
The
function which receives control is called a called
functions.
The
function which sends control through a function call is called a calling function.
In
the above program calling function is the main() and float area() and
floatarea2() are the called functions.