C Function Arguments & Return Value



Function with arguments and Return Value in C :

We have learnt different types of function calling. In this example we are going to learn function which can accept an argument and return a value.

Function accepts argument and it return a value back to the calling Program thus it can be termed as Two-way Communication between calling function and called function.

Live Program : Function with argument and return type

#include<stdio.h>
float calculate_area(int);
int main()
{
    int radius;
    float area;
    printf("\nEnter the radius of the circle : ");
    scanf("%d",&radius);
    area = calculate_area(radius);
    printf("\nArea of Circle : %f ",area);
    return(0);
}
float calculate_area(int radius)
{
    float areaOfCircle;
    areaOfCircle = 3.14 * radius * radius;
    return(areaOfCircle);
}

Output :

Enter the radius of the circle : 2
Area of Circle : 12.56

Explanation :

  1. In the above program we can see that inside main function we are calling a user defined calculate_area() function.
  2. We are passing integer argument to the function which after area calculation returns floating point area value.
  3. Re-commanded readings : Function without argument & return type and Function with Argument & No Return Value in C