Reputation:
The return data-type of a function,whose prototype is declared in main(), is void. It cointains an instruction return; as in
main()
{
void create(int *p);
*some code*
}
void create(node *list)
{
*some code*
return;
}
What will it return,and where will it return??
Upvotes: 3
Views: 18809
Reputation: 9050
In this case doesn't mean much.
return; means exit suddenly from this function returning void.
int a()
{
return 10;
}
void b()
{
return; // we have nothing to return, this is a void function.
}
void c()
{
// we don't need return; it is optional.
}
return; for a void function is not useful, it can be omitted, is optional. However sometime it is useful, for example, for exiting a loop or a switch.
void xxx()
{
int i = 0;
while (1)
{
if (++i >= 100)
return; // we exit from the function when we get 100.
}
}
Upvotes: 4
Reputation: 18492
It's not going to return anything, you might have return statements in a void function to kind of alter the flow and exit from the function. ie rather than:
void do_something(int i)
{
if (i > 1) {
/* do something */
}
/* otherwise do nothing */
}
you might have:
void do_something(int i)
{
if (i <= 1)
return;
/* if haven't returned, do something */
}
Upvotes: 9
Reputation: 20764
it will return from the executing function with a void
return value (which means no value).
Upvotes: 1
Reputation: 363567
return;
won't return anything, which matches the declared void
return type of the function create
. It will return to the caller of the function it appears in (not shown in your example), just like return EXPRESSION;
will.
In this particular piece of code, return;
is redundant since it appears at the very end of create
, but it's useful when you want to exit a function prematurely:
void print_error(char const *errmsg)
{
if (errmsg == NULL)
// nothing to print
return;
perror(errmsg);
}
Upvotes: 2