C++ キーワード: return
From cppreference.com
[編集] 使用法
- return 文: 文の宣言として
[編集] 例
このコードを実行
#include <cstdlib> #include <iostream> [[nodiscard]] constexpr auto clamp(int value, int min, int max) noexcept { if (value <= min) return min; else if (max <= value) return max; return value; // won't be executed past 'return' statement std::exit(value); } int main() noexcept { std::cout << clamp(1, 2, 4); std::cout << clamp(3, 2, 4); std::cout << clamp(5, 2, 4); return 0; // the value '0' that in main() indicates a success }
出力
234
[編集] 関連項目
|
(C++17以降) |
|
(C++23から) |
- switch ステートメント:
switch,case - default (case ラベル宣言として) など:
default - goto ステートメント:
goto - continue ステートメント:
continue - break ステートメント:
break
| (C++20以降) |