With Arguments and No Return Values Function

This “With Arguments and No Return Values Function” page providing clearly how to define a function in C programming which is taking input but not giving output.


 

With arguments and No return values function :

  • The function is taking input(arguments) but not return the values.
  • Return value must be specified by using “void” data type.
  • In this program, add() represents above classification.
  • In the declaration of prototype, no need to specify name of variables.

 

#include<stdio.h>
void add(int,int);
void main(void)
{
int a,b;
printf(“Enter two numbers\n”);
scanf(“%d%d”,&a,&b);
add(a,b);
}
void add(int a, int b)
{
int c;
c=a+b;
printf(“sum : %d\n”,c);
}

 

  • Arguments of a function working like local variables.
  • Local variables get memory allocation inside the Function Frame.
  • Once Function execution has been completed, Frame will by deleted.
  • All the local variables get destroyed along with Function Frame.

 

Program to check input number is Even or not:
#include<stdio.h>
void isEven(int);
void main(void)
{
int n;
printf(“Enter n value : \n”);
scanf(“%d”,&n);
isEven(n);
}
void isEven(int x)
{
if(x%2==0)
printf(“%d is Even \n”);
else
printf(“%d is not Even \n”);
}

Share this