Skip to content

Commit 257b0be

Browse files
committed
update:增加材料
Signed-off-by: YdrMaster <[email protected]>
1 parent 3912fbf commit 257b0be

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

exercises/02_function/main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
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

59
int main(int argc, char **argv) {

exercises/03_argument&parameter/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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+
56
void func(int);
67

78
// TODO: 为下列 ASSERT 填写正确的值

exercises/05_constexpr/main.cpp

+1
Original file line numberDiff line numberDiff 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;

exercises/06_loop/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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>
46
static unsigned long long fibonacci(int i) {
57
// TODO: 为缓存设置正确的初始值
68
static unsigned long long cache[96], cached;

exercises/07_enum&union/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ enum class Color : int {
2424
};
2525

2626
ColorEnum 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;

0 commit comments

Comments
 (0)