Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
return is a keyword that ends a function (or member function). Depending on the function, return might return anything or nothing.
The following function calculates the square of an integer:
///Calculates the square of an integer |
If a function returns nothing (that is, a return type of void), one can omit the final return:
#include <iostream> |
The function main is special. It returns an integer error code of the program, where a zero denotes a no-failure run. When main's closing bracket is reached, the effect is equivalent to (Standard, 3.6.1.5):
return 0; |
Therefore, the following two pieces of code are equivalent:
int main() {} |
int main() { return 0; } |
Program flow in a C++11 lambda expression differs from a C++98 lambda expression or BOOST_FOREACH: if you want to return from a function, all that happens is that the std::for_each (or other algorithm) is terminated. The example below shows this.
#include <algorithm> |
Screen output:
FOUND! |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.