C Function No Arguments & No C Function Arguments
Return Value
Return Value
#include<stdio.h>
void area(); // Prototype Declaration
void main()
{
area();
}
void area()
{
float area_circle;
float rad;
printf("\nEnter the radius : ");
scanf("%f",&rad);
area_circle = 3.14 * rad * rad ;
printf("Area of Circle=%f",area_circle);
}
&
No
#include<stdio.h>
#include<conio.h>
void area(float rad);
void main()
{
float rad;
printf("nEnter the radius : ");
scanf("%f",&rad);
area(rad);
getch();
}
void area(float rad)
{
float ar;
ar = 3.14 * rad * rad ;
printf("Area of Circle = %f",ar);
}
Function with argument and return Function with
type
return type
no argument but
#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);
}
#include<stdio.h>
float calculate_area();
int main()
{
float area;
printf("\nEnter the radius of the
circle : ");
area = calculate_area();
printf("\nArea of Circle: %f ",area);
return(0);
}
float calculate_area()
{
int radius;
float areaOfCircle;
scanf("%d",&radius);
areaOfCircle =3.14 * radius * radius;
return(areaOfCircle);
}
Function call by value
Function call by reference in C
This method copies the actual value of an
argument into the formal parameter of the
function. In this case, changes made to the
parameter inside the function have no effect on
the argument.
This method copies the address of an argument
into the formal parameter. Inside the function,
the address is used to access the actual
argument used in the call. This means that
changes made to the parameter affect the
argument.
#include <stdio.h>
/* function declaration */
void swap(int x, int y);
#include <stdio.h>
/* function declaration */
void swap(int *x, int *y);
int main ()
{
/* local variable definition */
int a = 100;
int b = 200;
int main ()
{
/* local variable definition */
int a = 100;
int b = 200;
printf("Before swap,value of a:%d\n",a );
printf("Before swap, value of a:%d\n", a );
printf("Before swap, value of b:%d\n", b );
swap(a, b);
printf("After swap, value of a: %d\n", a );
printf("After swap, value of b: %d\n", b );
return 0;
}
void swap(int x, int y)
{
int temp;
temp = x; /* save the value of x */
x = y;
/* put y into x */
y = temp; /* put temp into y */
}
return;
printf("Before swap,value ofb:%d\n",b );
swap(&a, &b);
printf("After swap,value of a:%d\n",a);
printf("After swap,value of b:%d\n",b );
return 0;
}
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
/* put
temp into y */
}
return;