Please see this program:

float area(float);
void main(void)
{
float radius;
printf ("Enter Radius");
scanf ("%d",&radius);
printf ("Area is %f",area(radius));
}
float area (float rad)
{
return (4*3.142*rad*rad);
}

please explain the above program, there no value has been assigned for rad then what does it mean ?
why it has been used ?
and what is mean by area(radius) in line 7

Edited 6 Years Ago by Xufyan: n/a

i've read that , the first page was so easy to understand but the 2nd page is so complex and used the source code that i haven't learned yet so how could i understand from your link ?

The variable "rad" is local to the area function. Whatever float is passed in to the area function is called "rad" for the scope of that function.

Your line 7 where it has "area(radius)", it's taking the radius input from the scanf line and passing that variable to the area function.

float area(float);

void main(void)
{
    float radius;
    printf ("Enter Radius");
    scanf ("%d",&radius);
    printf ("Area is %f",area(radius)); // Call the area function and pass in 
}

float area (float rad) // Function that takes in a single float and calls it rad
{
    return (4*3.142*rad*rad);
}

Functions/methods/procedures are pretty necessary parts of C, so it's something you might want to keep reading on until you fully understand how they work.

This article has been dead for over six months. Start a new discussion instead.