File tree 5 files changed +14
-3
lines changed
5 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
#include " ../exercise.h"
2
2
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
+
3
7
// TODO: 在这里声明函数
4
8
5
9
int 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
-
3
1
#include " ../exercise.h"
4
2
3
+ // READ: <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>
4
+ // THINK: 参数都有哪些传递方式?如何选择传递方式?
5
+
5
6
void func (int );
6
7
7
8
// TODO: 为下列 ASSERT 填写正确的值
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ int main(int argc, char **argv) {
17
17
std::cout << " fibonacci(20) = " << FIB20 << std::endl;
18
18
19
19
// TODO: 观察错误信息,修改一处,使代码编译运行
20
+ // PS: 编译运行,但是不一定能算出结果……
20
21
constexpr auto ANS_N = 90 ;
21
22
constexpr auto ANS = fibonacci (ANS_N);
22
23
std::cout << " fibonacci(" << ANS_N << " ) = " << ANS << std::endl;
Original file line number Diff line number Diff line change 1
1
#include " ../exercise.h"
2
2
3
3
// TODO: 改正函数实现,实现正确的缓存优化斐波那契计算
4
+ // THINk: 这个函数是一个纯函数(pure function)吗?
5
+ // READ: 纯函数 <https://zh.wikipedia.org/wiki/%E7%BA%AF%E5%87%BD%E6%95%B0>
4
6
static unsigned long long fibonacci (int i) {
5
7
// TODO: 为缓存设置正确的初始值
6
8
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 {
24
24
};
25
25
26
26
ColorEnum convert_by_pun (Color c) {
27
+ // READ: <https://zh.cppreference.com/w/cpp/language/union>
27
28
// `union` 表示在同一内存位置存储的不同类型的值。
28
29
// 其常见用法是实现类型双关转换,即将一种类型的值转换为另一种无关类型的值。
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>
30
33
union TypePun {
31
34
ColorEnum e;
32
35
Color c;
You can’t perform that action at this time.
0 commit comments