File tree Expand file tree Collapse file tree 5 files changed +14
-3
lines changed Expand file tree Collapse file tree 5 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 11#include " ../exercise.h"
22
3+ // READ: 声明 <https://zh.cppreference.com/w/cpp/language/declarations>
4+ // NOTICE: cppreference 中的示例中指出了复杂声明的解读法,建议认真阅读。
5+ // NOTICE: 补充由内而外读法的机翻解释 <https://learn.microsoft.com/zh-cn/cpp/c-language/interpreting-more-complex-declarators?view=msvc-170>
6+
37// TODO: 在这里声明函数
48
59int main (int argc, char **argv) {
Original file line number Diff line number Diff line change 1- // READ: <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>
2-
31#include " ../exercise.h"
42
3+ // READ: <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>
4+ // THINK: 参数都有哪些传递方式?如何选择传递方式?
5+
56void func (int );
67
78// TODO: 为下列 ASSERT 填写正确的值
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ int main(int argc, char **argv) {
1717 std::cout << " fibonacci(20) = " << FIB20 << std::endl;
1818
1919 // TODO: 观察错误信息,修改一处,使代码编译运行
20+ // PS: 编译运行,但是不一定能算出结果……
2021 constexpr auto ANS_N = 90 ;
2122 constexpr auto ANS = fibonacci (ANS_N);
2223 std::cout << " fibonacci(" << ANS_N << " ) = " << ANS << std::endl;
Original file line number Diff line number Diff line change 11#include " ../exercise.h"
22
33// TODO: 改正函数实现,实现正确的缓存优化斐波那契计算
4+ // THINk: 这个函数是一个纯函数(pure function)吗?
5+ // READ: 纯函数 <https://zh.wikipedia.org/wiki/%E7%BA%AF%E5%87%BD%E6%95%B0>
46static unsigned long long fibonacci (int i) {
57 // TODO: 为缓存设置正确的初始值
68 static unsigned long long cache[96 ], cached;
Original file line number Diff line number Diff line change @@ -24,9 +24,12 @@ enum class Color : int {
2424};
2525
2626ColorEnum convert_by_pun (Color c) {
27+ // READ: <https://zh.cppreference.com/w/cpp/language/union>
2728 // `union` 表示在同一内存位置存储的不同类型的值。
2829 // 其常见用法是实现类型双关转换,即将一种类型的值转换为另一种无关类型的值。
29- // READ: <https://zh.cppreference.com/w/cpp/language/union>
30+ // 但这种写法实际上仅在 C 语言良定义,在 C++ 中是未定义行为。
31+ // 这是比较少见的 C++ 不与 C 保持兼容的特性。
32+ // READ: 类型双关 <https://tttapa.github.io/Pages/Programming/Cpp/Practices/type-punning.html>
3033 union TypePun {
3134 ColorEnum e;
3235 Color c;
You can’t perform that action at this time.
0 commit comments