Return From Void Functions in C++
Void functions are known as Non-Value Returning functions. They are “void” due to the fact that they are not supposed to return values. True, but not completely. We cannot return values but there is something we can surely return from void functions. Void functions do not have a return type, but they can do return values. Some of the cases are listed below:
1) A Void Function Can Return: We can simply write a return statement in a void fun(). In fact, it is considered a good practice (for readability of code) to write a return; statement to indicate the end of the function.
2) A void fun() can return another void function: A void function can also call another void function while it is terminating. For example,
The void function has returned a void() !!!
The above code explains how void() can actually be useful to return void functions without giving errors.
3) A void() can return a void value: A void() cannot return a value that can be used. But it can return a value that is void without giving an error. For example,
This article is contributed by Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.