Return from Void Functions in C++



The void functions are called void because they do not return anything. "A void function cannot return anything" this statement is not always true. From a void function, we cannot return any values, but we can return something other than values. Some of them are like below.

A void function can return

A void function cannot return any values. But we can use the return statement. It indicates that the function is terminated.

Example

The following example demonstrates a void function with the return statement:

#include <iostream>
using namespace std;
void my_func() {
   cout << "From my_function" << endl;
   return;
}
int main() {
   my_func();
   return 0;
}

Following is the output to the above program:

From my_function

A void function can return another void function

You can also use a function having return type void inside a void function with return statement.

Example

In this example, one void function can call another void function while it is terminating that means, inside my_func(), it calls another_func() using the return statement. This doesn't return a value but instead executes another void function before it is fully exiting.

#include <iostream>
using namespace std;
void another_func() {
   cout << "From another_function" << endl;
   return;
}
void my_func() {
   cout << "From my_function" << endl;
   return another_func();
}
int main() {
   my_func();
   return 0;
}

Following is the output to the above program:

From my_function
From another_function
Revathi Satya Kondra
Revathi Satya Kondra

Technical Content Writer, Tutorialspoint

Updated on: 2025-06-10T13:16:07+05:30

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements