return statement
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
Met fin la fonction en cours et retourne la valeur spcifie pour la fonction appelante .
Original:
Terminates current function and returns specified value to the caller function.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Syntaxe
return expression
|
(1) | ||||||||
return
|
(2) | ||||||||
Explication
La premire version value la expression, met fin la fonction en cours et renvoie le rsultat de la expression la fonction. Le type rsultant de l'expression doit tre convertible fonctionner type de retour .
Original:
The first version evaluates the expression, terminates the current function and returns the result of the expression to the caller function. The resulting type of the expression must be convertible to function return type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
La deuxime version met fin la fonction en cours. Valable uniquement si le type de retour de la fonction est
void .Original:
The second version terminates the current function. Only valid if the function return type is
void.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Mots-cls
Exemple
#include <iostream>
void fa(int i)
{
if (i == 2) return;
std::cout << i << '\n';
}
int fb(int i)
{
if (i > 4) return 4;
std::cout << i << '\n';
return 2;
}
int main()
{
fa(2);
fa(1);
int i = fb(5);
i = fb(i);
std::cout << i << '\n';
}
Rsultat :
1
4
2