Search code examples
c++creturnvoid

What is the point of adding a return statement at end of a void function?


I see functions/methods with a void return in the signature that have a return statement at the end of the function. What is the reason for this, and does this apply to other languages?

For all I know, I can use return if I want to exit anywhere else but the end of the function.

A C example:

void function(void)
{
   int x = 1 + 2;

   return;    // what do we need this for, if at all?
}

Solution

  • This seems pointless here. But my guess is that this kind of thing can be used to put a breakpoint in IDEs which don't support putting a breakpoint at the closing brace and by putting a breakpoint here, some values can be checked in the watch window etc.