void, which means the function does not return a value
void, the function takes no parameters
int
add(int a, int b)
{
return a + b;
}
int
add(a, b);
int a, b;
{
return a + b;
}
int
a(){},
which is the same as the somewhat more explicit:
int
a(void)
{
}
though, since it doesn't return a value, it would be better defined as:
void
a(void)
{
}
int
factorial(int n)
{
if (n <= 1)
return 1;
else
return n * factorial(n - 1);
}
return statement exits the current function
return may also be given an expression whose value
is used as the value returned to the caller
add() function would look like:int add(int a, int b);
add() function could have been written asint add(int, int);
double dfunc(double d);
and, in another file, you do i = dfunc(3); (where i
is an int variable
and 3 is an int constant), the compiler will not
know that 3 should be passed as a double, so it
will not do the conversion and dfunc will not operate as expected
int name(); is assumed
#included
in every file where the function is called
void
subfunc(int a)
{
a = 3;
}
void
func(void)
{
int a, b;
a = 0;
subfunc(a);
b = a;
}
the b variable in func() would be set to 0, not 3,
since subfunc() operates on a copy of the value of
a, not the actual variable