Function with no arguments and with return value in C
In C, a function can return a value and also cannot accept any argument as input. This type of function can return value of any valid c data type like int, float, char, double etc.
To return a value from function return keyword is used followed by variable or value. It must be the last statement in function definition.
Function Declaration Syntax
<return_type> <function_name>();
Function Definition Syntax
<return_type> <function_name>()
{
// set of statements
return variable_name;
}
Function call Syntax
<function_name>();
Example
#include<stdio.h>
//Function Declaration
int addNumbers();
void main()
{
int c = 0;
c = addNumbers(); //Function call
printf("Sum is %d ", c);
}
// //Function Definition
int addNumbers()
{
int a = 20, b = 30, c = 0;
c = a + b;
return c; // Returning value
}