Ozymandias Ozymandias - 24 days ago 10
C++ Question

Why use void with a function?

I understand that void returns no values.
So how does it work in conjuncture to a function?

My understanding is that the purpose of a function is to return a piece of information after doing something with it.

so why would I want to return no value, and how would this be beneficiary?

Answer

My understanding is that the purpose of a function is to return a piece of information after doing something with it.

In some (most of the) programming languages, functions have side effects also. Purpose of some functions is limited only to side effects and return value is not necessary. Such functions have void return type.

Some examples of side effects may be:

  1. Update a global
  2. File operation, logging etc where user doesn't want to know the status of operation
  3. Freeing resources