C Language



Admission Enquiry Form

  

Function with Argument and with Return in C



Function with argument and with return value in C

Function with argument and with return means when calling function is giving some values to called function as arguments and called function is also returning a value to calling function.

Example:

#include<stdio.h>
#include<conio.h>
int num1,num2,res;//global variables
void main()
{
int sum(int,int); //declaration of function
printf("\nCalling sum fun");
printf("\nEnter two no's");
scanf("%d%d",&num1,&num2);
res=sum(num1,num2);   //call by value
printf("\nResult is %d",res);
printf("\nBye");
getch();
}//end of main
int sum(int n1,int n2)   //body of function
{
res=n1+n2;
return(res);
}


Output

Calling sum fun
Enter two no's50
90

Result is 140
Bye