C++ 关键字: return
来自 cppreference.cn
[编辑] 用法
- 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
[编辑] 参见
|
(since C++17) |
|
(since C++23) |
- switch 语句:
switch
,case
- default (作为 case 标签声明) 等:
default
- goto 语句:
goto
- continue 语句:
continue
- break 语句:
break
(since C++20) |