Void functions 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. Some of cases are listed below.
A void function can do return
We can simply write return statement in a void fun(). In-fact it is considered a good practice (for readability of code) to write return; statement to indicate end of function.
A void fun() can return another void function
The void function has returned a void() !!!
The above code explains how void() can actually be useful to return void functions without giving error.
A void() can return a void value.
A void() cannot return a value that can be used. But it can return a value which is void without giving an error.
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- void pointer in C / C++
- How does "void *" differ in C and C++?
- Dangling, Void , Null and Wild Pointers
- Is it fine to write "void main()" or "main()" in C/C++?
- Difference between "int main()" and "int main(void)" in C/C++?
- What does main() return in C and C++?
- Implicit return type int in C
- return statement in C/C++ with Examples
- Function overloading and return type
- How to return a local array from a C/C++ function?
- Using return value of cin to take unknown number of inputs in C++
- How to return multiple values from a function in C or C++?
- return statement vs exit() in main()
- Return values of printf() and scanf() in C/C++
- How can I return multiple values from a function?
- C function argument and return values
- What is return type of getchar(), fgetc() and getc() ?
- Functions in C/C++
- Searching in a map using std::map functions in C++
- C | Functions | Question 10