C Language



Admission Enquiry Form

  

Function with no argument and with return value in C



Function with no argument and with return value in C

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

Example:

#include<stdio.h>          
#include<conio.h>
int res;//global variable
void main()
{
int sum(); //declaration of function
printf("\nCalling sum fun");
res=sum();//calling
printf("\nResult is %d",res);
printf("\nBye");
getch();
}//end of main

 int sum()   //body of function
{
int num1,num2;
printf("\nEnter first number");
scanf("%d",&num1);
printf("\nEnter second number");
scanf("%d",&num2);
res=num1+num2;
return(res);                     
}


Output

Calling sum fun
Enter first number
222

Enter second number444

Result is 666
Bye