Зміст курсу
C++ Functions
C++ Functions
Void Return Type
In C++, the void
return type is used in functions to indicate that the function does not return any value. When a function has a void
return type, it means the function does its task without producing a result that needs to be used elsewhere in the program.
For example, let's consider the function that prints values of 1D dynamic array that we used before:
main
We can see that the purpose of this function is to print the array, and it doesn't produce any meaningful result that must be returned. So we can use void
return value in this case.
But you can still use return
in a void function. For example if you want to terminate it on certain condition.
main
Все було зрозуміло?